在DLL中嵌入基于MFC对话框的应用程序,并使用RunDll32运行
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在DLL中嵌入基于MFC对话框的应用程序,并使用RunDll32运行相关的知识,希望对你有一定的参考价值。
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) ;
BOOL CAppInDllApp::InitInstance() { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need // Change the registry key under which our settings are stored // TODO: You should modify this string to be something appropriate // such as the name of your company or organization SetRegistryKey(_T("Local AppWizard-Generated Applications")); CWinApp::InitInstance(); return TRUE; } void CALLBACK AppInDll_Entry(HWND hwnd, HINSTANCE hinst, LPCSTR lpCmdLine, int nCmdShow) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need // Change the registry key under which our settings are stored // TODO: You should modify this string to be something appropriate // such as the name of your company or organization /// SetRegistryKey(_T("Local AppWizard-Generated Applications")); CDlgInDll dlg; theApp.m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } }
以上是关于在DLL中嵌入基于MFC对话框的应用程序,并使用RunDll32运行的主要内容,如果未能解决你的问题,请参考以下文章
MFC中,如何连接sqlite3的数据库,并对此数据库操作??