如何使用 win32 在 D 中创建 Windows?
你好,我正在尝试在 D 中使用 win32 打开一个窗口,但遇到了一些问题。当我调用 CreateWindowA 时,程序崩溃了。
这是我的代码:
this.fenetrePrincipale = CreateWindowA(this.classeFenetre.lpszClassName, toStringz(title), WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, null, null, this.hInstance, null);
with:
this.classeFenetre.lpszClassName = toStringz("classeF");
this.hInstance = GetModuleHandleA(null);
当
string title = "test";
我启动exe时,程序崩溃了,我得到了:
进程终止,状态为-1073740791
进程在 code::blocks 上
Hello I'm trying to open a window with win32 in D, and I've got a little problem. The program crashes when I call CreateWindowA.
Here is my code :
this.fenetrePrincipale = CreateWindowA(this.classeFenetre.lpszClassName, toStringz(title), WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, null, null, this.hInstance, null);
with:
this.classeFenetre.lpszClassName = toStringz("classeF");
this.hInstance = GetModuleHandleA(null);
and
string title = "test";
When I launch the exe, the program crashes and I've got:
Process terminated with status -1073740791
on code::blocks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
错误代码-1073740791(或0xc0000409)是由堆栈缓冲区溢出引起的(不是溢出,如耗尽堆栈,而是写入堆栈中不应该写入的位置)。
您显示的通话看起来没问题。但您没有向我们展示类注册代码,更重要的是,您注册的
WndProc
。我不确定你如何在 D 中执行此操作,但是你的WndProc
需要声明__stdcall
,以便它符合 Windows 假定的调用约定。这是导致CreateWindow
崩溃的常见问题。The error code -1073740791 (or 0xc0000409) is caused by a stack buffer overrun (not overflow, as in running out of stack, but writing to a place in stack where you are not supposed to write to).
The call that you've shown is looks OK. But you didn't show us the class registration code, and more importantly, the
WndProc
you register. I am not sure how you do it in D, but yourWndProc
needs to be declared__stdcall
, so that it matches the calling convention assumed by Windows. This is a common problem that causes crashes onCreateWindow
.是的,这就是问题所在:
我没有将 WndProc 声明为 __stdcall
你在 D 中这样做的方式是
感谢你的帮助。
Yeah that was the problem :
I didn't declared the WndProc as __stdcall
the way you do that in D is
thanks for your help.
我建议使用 gtkD 或 QTD 而不是 Win32。这两个小部件库成熟且功能强大,但使用起来非常简单。而且您还拥有跨平台支持。
I would suggest using gtkD or QTD instead of Win32. The two widget libraries are mature and powerful, yet very simple to use. And you have cross-platform support as well.