Click here to Skip to main content
15,906,333 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have C++ dll that using by another software. I need when software call one function of this dll , it shows one Dialog for get user/pwd. My code before worked but in this time not works.
C++
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;
}


I added resource to dll too and compile without problem. but when call this function it not works and not shows dialog box.
Any bug in my code?
Regards,
Posted
Comments
chandanadhikari 18-Sep-13 9:16am    
please try to debug by placing breakpoints in this code.Maybe this dll is not getting loaded correctly .
MyOldAccount 18-Sep-13 19:21pm    
It seems that you pass NULL as lParam to your CreateDialogParam().

Maybe you have forgotten to pass a structure?

In your WM_INITDIALOG you should convert lParam to that structure and use it the way you want.

That is the purpose of CreateDialogParam right?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900