我有另一个软件使用的 C++ dll。我需要当软件调用此 dll 的一项功能时,它会显示一个获取用户/密码的对话框。我的代码之前工作过,但这次不起作用。
INT_PTR CALLBACK DialogFunc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
g_hInstance = hModule;
bRun = FALSE;
dwNewLong = 0;
g_Msg = RegisterWindowMessageA("MetaTrader4_Internal_Message");
g_hWnd = FindWindowA("TForm1", "Form1");
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
HWND hWnd1;
int nRet;
char b1[]="VALID";
HWND g_hDlg2,hWnd,hDlg2,hDlg3;
INT_PTR CALLBACK DialogFunc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
read(f1);
read1(f2);
hDlg1=GetDlgItem(hDlg,IDC_EDIT1);
SetWindowTextA(hDlg1,UserSaved);
hDlg2=GetDlgItem(hDlg,IDC_EDIT2);
SetWindowTextA(hDlg2,PWDSaved);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BUTTON2:
hDlg3=hDlg;
GetWindowText(hDlg1,username,1024);
write(f1);
GetWindowText(hDlg2,key,1024);
write1(f2);
if(memcmp(Get_Account_Number_FromWEB(),b1,sizeof(b1))==0 ){result=1; DestroyWindow(hDlg);}
else MessageBox(0,TEXT("Wrong User or PWD"),0,0);
break;
case IDC_BUTTON3:
DestroyWindow(hDlg);
break;
case IDC_EDIT1:
break;
case IDC_EDIT2:
break;
}
break;
case WM_CLOSE:
SetWindowLongA(hDlg, GWL_WNDPROC, dwNewLong);
DestroyWindow(hDlg);
return TRUE;
break;
}
return FALSE;
}
int aa=0;
HWND hWnd2;
int dd;
HWND hDlg;
MT4_EXPFUNC int __stdcall INITIAL(HWND hWnd)
{
MSG msg;
BOOL msgstatus;
if(aa==0){
hDlg = CreateDialogParamA(g_hInstance, MAKEINTRESOURCE(IDD_DIALOG1 ), hWnd, DialogFunc, 0);
SetWindowPos( hDlg, HWND_TOPMOST,0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | WS_EX_TOPMOST );
ShowWindow(hDlg, SW_SHOW);
aa=1;
}
dd=result;
hWnd2=hWnd;
return result;
}
我也向 dll 添加了资源并且编译没有问题。但是当调用这个函数时它不起作用并且不显示对话框。我的代码中有任何错误吗?问候,