简体   繁体   English

CallWindowProc() 生成错误 5(访问被拒绝)

[英]CallWindowProc() generates error 5 (Access is denied)

I'm trying to resolve error, that I get with GetLastError() during execution of CallWindowProc .我正在尝试解决在CallWindowProc执行期间使用GetLastError()遇到的错误。 The code is as follows:代码如下:

static LRESULT CALLBACK editSubProc(HWND h, UINT m, WPARAM w, LPARAM l)
{
//some implementation
//GetLastError() returns 0 here
CallWindowProc(edit_proc,h,m,w,l);
}

Creation of window looks like below:窗口的创建如下所示:

HWND ch=CreateWindowEx(style,"Edit","",dwstyle,l,t,r-l,b-t,hwnd,0,hInst,0);
edit_proc=(WNDPROC)GetWindowLongPtr(ch,GWLP_WNDPROC);
SetWindowLongPtr(ch,GWLP_WNDPROC,(LONG_PTR)editSubProc);

Now, the scenario is, that main loop calls IsDialogMessage(...) , which invokes editSubProc , which,through CallWindowProc , again invokes editSubProc .现在,场景是,主循环调用IsDialogMessage(...) ,它调用editSubProc ,它通过CallWindowProc再次调用editSubProc On the beggining of second invokation of editSubProc , GetLastError returns 5. Everything is invoked from the same thread.在第二次调用editSubProcGetLastError返回 5。一切都从同一个线程调用。 What could be the reason of such behavior?这种行为的原因是什么?

GetLastError() returns the last error that happened (it even says so in the name!). GetLastError()返回发生的最后一个错误(它甚至在名称中这么说!)。

So the last error that happened was "access denied".所以最后发生的错误是“访问被拒绝”。

When did it happen?什么时候发生的? No clue.没有线索。 Was it supposed to happen?它应该发生吗? No idea.不知道。 Is it a problem?这是个问题吗? Probably not.可能不是。 There are lots of reasons why access might be denied to something , and perhaps some part of the Windows OS just wanted to see whether it had access to something.某些内容的访问可能被拒绝的原因有很多,也许 Windows 操作系统的某些部分只是想看看它是否可以访问某些内容。

You should call GetLastError when you get an error and the documentation tells you to call it to get the error code .您应该在收到错误时调用GetLastError并且文档告诉您调用它来获取错误代码 Otherwise you just get whatever the last error that happened was, which might be a completely different part of the program, maybe where there was supposed to be an error.否则你只会得到最后发生的错误,这可能是程序的一个完全不同的部分,也许是应该出现错误的地方。 You're making up imaginary problems, where none exist.你在编造假想的问题,而这些问题根本不存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM