I have created a Win32 dll in Visua Studio 2015 that contains a dialog box, I use the hModule passed to DllMain ()
and use ShowWindow ()
to actually show the window, but dialog box doesn't show up.
I use LoadLibrary()
to load this DLL in another project.
Where is the problem? Here is my code:
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved,
HINSTANCE hinstDLL
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
HWND hDlg;
MSG msg;
BOOL ret;
BOOL sts;
InitCommonControls();
hDlg = CreateDialogParam(hinstDLL, MAKEINTRESOURCE(IDD_DIALOG1), 0, DialogProc, 0);
if (!hDlg) {
MessageBoxA(NULL,GetLastErrorAsString().c_str(),"",MB_OK);
return false;
}
sts = ShowWindow(hDlg, 1);
if (!sts)
{
MessageBoxA(NULL, GetLastErrorAsString().c_str(), "", MB_OK);
return false;
}
while ((ret = GetMessage(&msg, 0, 0, 0)) != 0) {
if (ret == -1)
return -1;
if (!IsDialogMessage(hDlg, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}