Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create Windows in D with win32?

Tags:

winapi

d

win32gui

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.

like image 414
Alexandre Hoffmann Avatar asked Dec 16 '22 08:12

Alexandre Hoffmann


2 Answers

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 your WndProc needs to be declared __stdcall, so that it matches the calling convention assumed by Windows. This is a common problem that causes crashes on CreateWindow.

like image 125
vhallac Avatar answered Jan 02 '23 17:01

vhallac


Yeah that was the problem :

I didn't declared the WndProc as __stdcall the way you do that in D is

extern (Windows) int windowRuntime(HWND window, UINT message, WPARAM wParam, LPARAM lParam)

thanks for your help.

like image 26
Alexandre Hoffmann Avatar answered Jan 02 '23 18:01

Alexandre Hoffmann