embed an MFC dialog-based app in a DLL and run using RunDll32


/ Published in: C++
Save to your folder(s)

This approach allows an application to be embedded in a DLL. This is handy for diagnostic/maintenance utilities that are used with the DLL.

Steps to create:
* Create a MFC DLL project
* Add a dialog
* Add an entry point function such as void CALLBACK AppInDll_Entry(HWND hwnd, HINSTANCE hinst, LPCSTR lpCmdLine, int nCmdShow)
* In this new function, do this:
CDlgInDll dlg;
theApp.m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
* in CAppInDllApp::InitInstance(), do this
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);

SetRegistryKey(_T("Local AppWizard-Generated Applications"));

CWinApp::InitInstance();
* Launch the 'app' using runDll32, for example:
rundll32 AppInDll.dll AppInDll_Entry a b c
or
ShellExecute( NULL, "open", "c:\\windows\\system32\\rundll32.exe", "AppInDll.dll AppInDll_Entry a b c", NULL, SW_SHOWNORMAL) ;

URL: http://www.codeproject.com/KB/DLL/eventrecorder.aspx

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.