:
int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
{
g_hMainWnd=CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)DialogProc);
RECT rcWnd;
GetWindowRect(g_hMainWnd,&rcWnd);
int X=(GetSystemMetrics(SM_CXSCREEN)-rcWnd.right+rcWnd.left)>>1,
Y=(GetSystemMetrics(SM_CYSCREEN)-rcWnd.bottom+rcWnd.top)>>1;
MoveWindow(g_hMainWnd,X,Y,rcWnd.right-rcWnd.left,rcWnd.bottom-rcWnd.top,FALSE);
ShowWindow(g_hMainWnd,SW_SHOW);
BOOL bRet;
MSG msg;
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
MessageBox(NULL,_T("GetMessage error with -1 returned!"),_T("error"),MB_ICONHAND);
break;
}
else if (!IsWindow(g_hMainWnd) || !IsDialogMessage(g_hMainWnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
我首先将项目设置更改为输出dll。 然后我将WinMain改为:
BOOL APIENTRY DllMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
{
g_hMainWnd=CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)DialogProc);
HWND hMainWnd;
//DialogProc involves the critical initialization of the data required for the export function used later
return 0;
}
那么,如果这是一个愚蠢的想法,或者我错过了什么? 谢谢大家!
答案 0 :(得分:0)
BOOL WINAPI DllMain(
HINSTANCE hinstDLL, // handle to DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpReserved ) // reserved
{
// Perform actions based on the reason for calling.
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
// Initialize once for each new process.
// Return FALSE to fail DLL load.
break;
case DLL_THREAD_ATTACH:
// Do thread-specific initialization.
break;
case DLL_THREAD_DETACH:
// Do thread-specific cleanup.
break;
case DLL_PROCESS_DETACH:
// Perform any necessary cleanup.
break;
}
return TRUE; // Successful DLL_PROCESS_ATTACH.
}
了解更多信息:Dll entry point
答案 1 :(得分:0)
DllMain的定义将由操作系统使用,有时您必须输入其代码。要执行实现EXE的代码,必须创建一个接收所需参数的公共例程。
使用Visual Studio创建一个库项目以导出一些数据和函数。
新项目 - &gt; 选择Viasual c ++ - &gt; 选择Win32 - &gt; Win32项目 - &gt; 名称您的项目 - &gt; 下一步 - &gt; 选择DLL - &gt; 选择导出符号 - &gt; 完成<登记/>
最终项目将包含一个正在导出的变量和一个公共例程。在代码中用作模板。