Thread: RE: [GD-Windows] CreateDialog failure
Brought to you by:
vexxed72
From: Brian S. <bs...@mi...> - 2002-08-24 17:06:19
|
I mostly use MFC for these sorts of things but here are some ideas to = try: * are you sure hInstance is the instance handle to your dll and not the = app? otherwise LoadResource on the dialog resource will fail * is hWnd a fully created window, or is it one you're in the process of = creating? have you tried passing NULL for the parent? * Is NULL a valid value for the DialogProc? Should it be DefDlgProc? * If you replace your call with MessageBox(...) does everything work? Unfortunately I do not know the answer to your real problem, but here's = a timesaving tip: typing "err,hr" into a watch window in the debugger = saves you the hassle of calling GLE/FormatMessage/etc. --brian -----Original Message----- From: Pierre Terdiman [mailto:p.t...@wa...] Sent: Sat 8/24/2002 7:18 AM To: gam...@li... Cc:=09 Subject: [GD-Windows] CreateDialog failure Hi, I create a dialog using something like : handle =3D CreateDialog( hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, NULL); But returned handle is null, which means (I guess) something went wrong. So I tried : DWORD Er =3D GetLastError(); Then retrieving the error string using FormatMessage (using the code = snippet from the MSDN). But it doesn't help since error code is 0 and = the translated string says there was no error. Hmm. What do I do now ? What are the usual reasons for CreateDialog to fail ? In case it's important, the call takes place in a DLL dynamically loaded = by a 3DS MAX plug-in, and hInstance and hWnd used to create the dialog = are the ones from the MAX plug. Pierre |
From: Pierre T. <p.t...@wa...> - 2002-08-25 18:16:35
|
>are you sure hInstance is the instance handle to your dll and not the app? >otherwise LoadResource on the dialog resource will fail Ok, it finally works but I'm still puzzled. In short, the instance handle was indeed wrong. - At first I was using the instance handle from the MAX window (in DLL 0, say), whereas the requested dialog resource was located in my new DLL, say DLL 1. No way it could have worked. Nonetheless, there was no clear error code/message to tell me I was doing something wrong, which is a bit clumsy. - Then, I tried using GetModuleHandle() with various parameters, to get back the instance handle from DLL 1. I would have expected GetModuleHandle(NULL) to work. Nope, it never made any difference. It also took me a while to figure out that HMODULE was actually the same as HINSTANCE. - Finally, I added a DllMain function in DLL 1. It wasn't there already since DLL 1 is a plug-in only exposing a limited set of functions to DLL 0. From there, I keep track of the HANDLE parameter, static-cast it to a HINSTANCE in a very very ugly way, use this for CreateDialog().... and it works ! Casting from HANDLE to HINSTANCE was only a hunch, and not an obvious one since the implicit cast fails to compile. It looks extremely ugly and I don't know if it's common practice or anything, but that's the only thing that seems to work so far. If there's a better way to get back the correct HINSTANCE, tell me... (you guessed it, I'm not really the Win32 API expert) - For the records, using hWnd from DLL 0 as a parent seems to work, and using NULL for the DialogProc works as well. - Now, I have another problem. The created dialog contains a bitmap, that is correctly displayed until I try to recenter the dialog.... When I do that, using SetWindowPos(), the dialog gets centered correctly, but the bitmap disappears ! This is insane. The SetWindowPos() parameters look insane as well. I just want X and Y, bloody hell ! Right now here's what I have : SetWindowPos(hWnd, NULL, x, y, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOOWNERZORDER); Any idea why it makes a bitmap contained in the dialog whose handle is hWnd disappear .....? Anyway thanks for the hints so far, it helped. Pierre PS: for various reasons I can't use MFC in DLL 1, even if I do in DLL 0. |
From: Pierre T. <p.t...@wa...> - 2002-08-25 20:48:06
|
> From there, I keep track of the HANDLE parameter, static-cast it to a > HINSTANCE in a very very ugly way, use this for CreateDialog().... and it Ok my mistake. I copy-pasted a DllMain() function from another source code, that was using a HANDLE parameter, but it's actually defined as a HINSTANCE in the MSDN. Seems to work just as well with a HANDLE nonetheless. (And I finally noticed there was a "Center" style in the resource editor so I'm using this right now.) Pierre |
From: Pierre T. <p.t...@wa...> - 2002-08-25 20:58:35
|
> - Then, I tried using GetModuleHandle() with various parameters, to get back > the instance handle from DLL 1. I would have expected GetModuleHandle(NULL) > to work. Nope, it never made any difference. It also took me a while to > figure out that HMODULE was actually the same as HINSTANCE. ....and of course after reading the docs more carefully I finally made it work, simply passing the DLL name as a parameter. Next time I'll RTFM twice. Pierre |