4

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.

menjaraz
  • 7,551
  • 4
  • 41
  • 81

3 Answers3

11

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.

vhallac
  • 13,301
  • 3
  • 25
  • 36
1

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.

  • 4
    Note this is not a forum, but a Q&A site, and as such you've posted an "answer". If you want to comment on an answer, click the comment button below it. If an answer is satisfactory, accept it by clicking the check mark. As for this "answer", you ought to delete it. Welcome! – GManNickG Oct 04 '11 at 07:45
0

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.

Ethan
  • 1,488
  • 3
  • 19
  • 24
  • In fact my aim is to create a 2D API from nothing. I don't want to create a proffessional like QT or GTK, more like sdl. – Alexandre Hoffmann Oct 07 '11 at 16:05
  • Why? Does it worth it to reinvent the wheel? In this case, there are some other GUI toolkit, although they are not mature yet, are written entirely in D. You can learn from their source code. And MSDN documentations is extremely valuable. – Ethan Oct 08 '11 at 00:52