[Win32 API] Cannot create Main Dialog

Hello,

I wasn't programming anything for like 1 month, so I decided to make something to school, but I'm having problem with creating main dialog... I have some "base" code that I'm using for every win32 api application because I'm lazy to create wndclass and other things

simply I have totally basic win32 api application done and saved, so I copied it, changed ID of dialog but it can't create it, it will create class but not the dialog, with those debug "points" I've discovered that it will go through

1
2
3
4
5
6
7
8
	HWND hWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_MAIN1), NULL, NULL);

	if(!hWnd)
	{
		int nResult = GetLastError();
		MessageBox(NULL, "Dialog Creation Failed!", NULL, MB_ICONERROR | MB_OK);
		return 0;
	}


but it will stop at "int nResult" so it won't create MessageBox

I have really no idea what's wrong there because I was using this base code in several applications, I've had several problems with it too but not like this one...

full source code with resources:

http://pastebin.com/GLSDmqGY
Strange. Let me see if I get this right: You are saying that your application freezes in the call to GetLastError() and never returns? If yes, what's the full call stack? And are you multi-threading? Maybe threads are not relevant, but just in case.

FYI, when I ask for the call stack, I mean one call stack with symbols identified. Have your Visual Studio download symbols from the MS server (Options, debugging, symbols). If you don't use Visual Studio, then I don't know how you can download symbols.
The fourth parameter to CreateDialog is the address of a Dialog Procedure. You are passing in null.
@webJose no, it will go to GetLastError() and exit immediately, so it will exit BEFORE MessageBox, here is the debug output:

edit: well as I can hear it IS creating MessageBox but it will close it immediately without showing it up

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'Matika.exe': Loaded 'C:\Users\Mekkatorqu\Documents\Visual Studio 2010\Projects\Matika\Release\Matika.exe', Symbols loaded.
'Matika.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\msvcr100.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\ProgramData\Real\RealPlayer\BrowserRecordPlugin\Chrome\Hook\rpchrome150browserrecordhelper.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57\msvcr90.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Program Files (x86)\SweetIM\Messenger\mgAdaptersProxy.dll', Binary was not built with debug information.
'Matika.exe': Loaded 'C:\Program Files (x86)\SweetIM\Messenger\msvcr71.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Program Files (x86)\RelevantKnowledge\rlls.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\ws2_32.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\nsi.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\oleacc.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\wininet.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\normaliz.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\iertutil.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\urlmon.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\psapi.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\ntmarta.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\Wldap32.dll', Cannot find or open the PDB file
First-chance exception at 0x7671b9bc in Matika.exe: Microsoft C++ exception: Win32Util::Error at memory location 0x003ce9bc..
'Matika.exe': Loaded 'C:\Windows\SysWOW64\schannel.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\crypt32.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\msasn1.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Program Files (x86)\DigitalPersona\Bin\DpOFeedb.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\userenv.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\profapi.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7600.16661_none_420fe3fa2b8113bd\comctl32.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Windows\SysWOW64\clbcatq.dll', Cannot find or open the PDB file
'Matika.exe': Loaded 'C:\Program Files (x86)\DigitalPersona\Bin\DpOSet.dll', Cannot find or open the PDB file
The thread 'Win32 Thread' (0x27dc) has exited with code 0 (0x0).
The program '[16176] Matika.exe: Native' has exited with code 0 (0x0).



@freddie1 I have pointed to DlgProc in wndclass

1
2
	wClass.lpfnWndProc=(WNDPROC)MainDlgProc;
	wClass.lpszClassName="Window Class";

CLASS "Window Class"
Last edited on
That's not the call stack.

As for GetLastError(), let me see if I understand now: You are saying that your program crashes at the moment GetLastError() is invoked? Does it throw an error message, or simply closes silently? Have you run the code one step at a time to see how the code progresses and verify the exact line where the process simply exits (if it exits silently)?
it will DO MessageBox and return 0, but the messagebox will NOT appear (I can hear only sound) and it will immediately exit, without any error, just like when I normally close application, so it has some problem with creating Dialog, which is weird cuz I've used that base code for every application I've did and I haven't problems liek this
Ok, so what is the error number returned by GetLastError()? That's key. Also why do you speak of a WNDCLASS structure?? That is meaningless if you use CreateDialog(), making it necessary to provide the window procedure as the fourth parameter to CreateDialog(). You are not using CreateWindow() or CreateWindowEx(), meaning you are not using a WNDCLASS or WNDCLASSEX structure anywhere.

So freddie1 may very well be right on the money.
You MUST have a WNDCLASS structure if the dialog is your main window. Thus, you do NOT insert a function parameter in the CreateDialog() call.

Moreover, your cbWndExtra member of the WNDCLASS structure MUST be set to DLGWINDOWEXTRA, like this --

wcex.cbWndExtra=DLGWINDOWEXTRA

There's more, and I suspect this is where your problem is, as well as the above if you haven't set your member as I just described.

First off, you need to entirely get rid of the MAKEINTRESOURCE parameter and replace it by first defining the classname in your header and then using that classname in this paramter, like so -

#define szClassName "MyMainDialog"

Now your CreateDialog() would be -

HWND hWnd = CreateDialog(hInst, szClassName, 0, NULL);

This is the proper way to do it according to Petzold, and I have created scores upon scores upon scores of main dialogs this way.

But there's still one more step.

In your resource file, the syntax MUST BE EXACT, like this -

1
2
3
MyMainDialog DIALOG 0,0,250,250
STYLE DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_GROUP | WS_POPUP | WS_SYSMENU
CLASS szClassName


In other words, notice NO QUOTES for MyMainDialog. Notice also that the CLASS parameter MUST BE STATED and it MUST MATCH the classname in your definition file.

Of course, you can set the style anyway you want, and also you can set the size of the dialog anyway you want, but you MUST adhere to these basic rules to get your dialog box to show if it is the main window of your Win32 app.
Last edited on
@Lamblion I don't need anything of that what you said, only cbWndExtra, which I have, how I said, I've created like 10 Dialog based applications with this base form, and this is first time I got this problem, IT WAS THE SAME CODE

btw with your version I'm getting this

resource.rc(20): error RC2104: undefined keyword or key name: szClassName

@webJose error code is 0...
Last edited on
What does the word "undefined" mean? Do you know?

Of course you need what I said, that why it is giving you the UNDEFINED error.

Because you haven't DEFINED your classname as I told you to.

You also have to make the "lpszClassName" member of your WNDCLASS structure equal szClassname, like this -

wcex.lpszClassName=szClassName;
@Lamblion: The two forms are correct. It depends entirely on what you want. Your way is the "hybrid" way (more simply described as the window created via a template, in Petzold's words). I had forgotten about this one altogether.
The problem is that creating a main dialog as the main window of the app any other way than what I've described ala Petzold can cause instability and problems with the application as it runs.

The way I've described ala Petzold makes the program completely stable and reliable. As I said, I've created more main dialogs than I can count, and this is the only way I've ever found them to be completely stable and reliable.

Go to this link and download the first two software apps, i.e., Quick Launcher and Conversion Utility for an example of using CreateDialogEx() as the main window of the application -

http://www.lamblion.net/Links%20&%20Software/_links_software_main.html
@Lamblion please read one more time what I've said, thanks
Please read what I said one more time. You're the one who can't make CreateDialog() work, not me. Nor can you understand your error message.

Those are two problems of yours, not mine. I don't have those problems. My apps actually work. Yours don't. Get it?

Just download the two programs from the link above and see which one of us is having the problem and which one is not.

You either haven't DEFINED szClassName in your header file or you haven't made the DEFINITION available in your resource file. That is EXACTLY what the error message reads.

I'm through with this. The evidence of who can and who can't make the app work is plain. I've given you all anyone needs to make the app work. The rest is up to you.

I should also add, by the way, that my way (Petzold's way), makes the program stable and allows full compatibility with using GetMessage() in WinMain instead of having to use dialog messages for the main window procedure, thus allowing far more flexibility with the program as a whole.
Last edited on
I'm not going to use Petzold's way because I'm using editor to make resources, and adding/editing resource and headers on my own will totally fuck it up, I don't remember that I've said anywhere in post that I wanna use Petzold's way or something
You couldn't be more wrong. I use an editor to make my resources also, and it doesn't affect anything whatsoever.

But since you know more than Petzold and me, even though Petzold and I can make CreateDialog() work, and you can't, have at it. Best of luck.
Topic archived. No new replies allowed.