Re: [GD-Windows] CreateDialog failure
Brought to you by:
vexxed72
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. |