Click to See Complete Forum and Search --> : dialog box inside a win32 dll


schumi1980
June 4th, 2004, 07:01 PM
Hi everyone !!!

This is the problem i am facing. I am exporting a function from a dll that pops up a dialogbox ( which i created at design time using Insert>Resource>Dialog..)

Now when i call the dll inside another application, the dialogbox doesnt pop up. please lemme how this is to be done. This is the code so i have been working with. Thanks in advance

include "windows.h"
#include "resource.h"

LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(wParam)
{
case IDA:
// TO DO
EndDialog(hWndDlg, 0);
return TRUE;
case IDB:
// TO DO
EndDialog(hWndDlg, 0);
return TRUE;
}
case WM_CLOSE:
EndDialog(hWndDlg, 0);
return TRUE;
break;
}
return FALSE;
}

void __declspec(dllexport) brow()
{
DialogBox((HINSTANCE)GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DLGFIRST), NULL, (DLGPROC)DlgProc);
}



BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved )
{
return TRUE;
}

rmsimpson
June 5th, 2004, 08:35 AM
That's an easy one ... look at the API docs for GetModuleHandle() and you'll see that if you pass NULL, you get the module handle for the EXE process, not the handle for your DLL. You need to record the hModule from DllMain() in a global variable somewhere and pass that handle to DialogBox().

Robert

NoHero
June 5th, 2004, 12:18 PM
#include "windows.h"
#include "resource.h"

HMODULE hInst;

LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(wParam)
{
case IDA:
// TO DO
EndDialog(hWndDlg, 0);
return TRUE;
case IDB:
// TO DO
EndDialog(hWndDlg, 0);
return TRUE;
}
case WM_CLOSE:
EndDialog(hWndDlg, 0);
return TRUE;
break;
}
return FALSE;
}

void __declspec(dllexport) brow()
{
DialogBox((HINSTANCE)hInst, MAKEINTRESOURCE(IDD_DLGFIRST), NULL, (DLGPROC)DlgProc);
}



BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved )
{
hInst = (HMODULE)hModule;
return TRUE;
}


does this work???

schumi1980
June 5th, 2004, 04:40 PM
hey guys,

thanks a lot for your replies and the code does work fine !!!

cheers