Click here to Skip to main content
15,922,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello can somebody advice me about how should i define the DialogInvoke function in my dll project, here is my working code, i compiled it in dll and want to use the DialogInvoke function in another project

Objective-C
#include<windows.h>
#include<windowsx.h>
#include<commctrl.h>
#include<shlobj.h>

#include "resource.h"

//Handles for the windows
HWND hdialog;
HINSTANCE ghInstance;
HWND edit;
//Folder Name that has been selected
TCHAR FolderName[MAX_PATH];
TCHAR c[MAX_PATH];
//Return value of the SHGetPathFromIDList
BOOL t;



void SetFont(HWND hwnd,LPTSTR FontName,int FontSize)
{
	
	HFONT hf;
	LOGFONT lf={0};
	HDC hdc=GetDC(hwnd);
	
	GetObject(GetWindowFont(hwnd),sizeof(lf),&lf);
	lf.lfWeight = FW_REGULAR;
	lf.lfHeight = (LONG)FontSize;
	lstrcpy( lf.lfFaceName, FontName );
	hf=CreateFontIndirect(&lf);
	SetBkMode(hdc,OPAQUE);
	SendMessage(hwnd,WM_SETFONT,(WPARAM)hf,TRUE);
	ReleaseDC(hwnd,hdc);
   
}


int __stdcall BrowseCallbackProc(HWND  hwnd,UINT  uMsg,LPARAM  lParam,LPARAM  lpData)
{


	if(uMsg==BFFM_INITIALIZED)
	{
		
		RECT ListViewRect,Dialog;
	
		edit=CreateWindowEx(0,"EDIT","",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_AUTOHSCROLL,0,100,100,50,hwnd,0,ghInstance,NULL);
		HWND caption=CreateWindowEx(0,"STATIC","You have selected the folder :",WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN,0,100,100,50,hwnd,0,ghInstance,NULL);
		HWND ListView=FindWindowEx(hwnd,NULL,"SysTreeView32",NULL);

		
		GetWindowRect(hwnd,&Dialog);
		GetWindowRect(ListView,&ListViewRect);

		
		SetWindowPos(ListView,0,(ListViewRect.left-Dialog.left) ,(ListViewRect.top-Dialog.top )-20,290,170,0);
	
		SetWindowPos(edit,HWND_BOTTOM,(ListViewRect.left-Dialog.left),(ListViewRect.top-Dialog.top )+170,290,18,SWP_SHOWWINDOW);
		SetWindowPos(caption,HWND_BOTTOM,(ListViewRect.left-Dialog.left),(ListViewRect.top-Dialog.top )+155,290,14,SWP_SHOWWINDOW);
        



	
		SetFont(caption,"MS Sans Serif",12);
		SetFont(edit,"MS Sans Serif",12);
		
	}

	
	if  (uMsg==BFFM_SELCHANGED)
	{
		t = SHGetPathFromIDList((ITEMIDLIST*)lParam, c);
            
		
		SetWindowText(edit,c);
		
    }
	
	return 0;
}


BOOL CALLBACK MainDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	if(message==WM_QUIT||message==WM_CLOSE)
		PostQuitMessage(0);

	if(message==WM_INITDIALOG)
	{
		
		hdialog=hDlg;
		
		RECT rc;

		GetWindowRect(hDlg,&rc); 
		int w=rc.right-rc.left, h=rc.bottom-rc.top;
		int cx=GetSystemMetrics(SM_CXSCREEN)/2, cy=GetSystemMetrics(SM_CYSCREEN)/2;
		MoveWindow(hDlg,cx-w/2,cy-h/2,w,h,FALSE);
		SendMessage(hDlg, WM_COMMAND, IDOK, 0);
		SendMessage(hDlg, WM_COMMAND, IDCANCEL, 0);
      
	}

	if(message==WM_COMMAND)
	{
		if((LOWORD(wParam))==IDOK)
		{
			
			TCHAR dname[MAX_PATH];
			IMalloc *imalloc; SHGetMalloc(&imalloc);
			BROWSEINFO bi; ZeroMemory(&bi,sizeof(bi));
			   
			bi.hwndOwner=hDlg;
			bi.pszDisplayName=dname;
			bi.lpszTitle = TEXT("Choose Directory");
			   
			#define BIF_NONEWFOLDERBUTTON  0x0200
			   
			bi.ulFlags = BIF_NONEWFOLDERBUTTON|BIF_RETURNONLYFSDIRS;
			bi.lpfn = BrowseCallbackProc;
			ITEMIDLIST *pidl = SHBrowseForFolder(&bi);
               
			   
			if (pidl!=NULL)
				MessageBox(hDlg,c,"Selected Folder",0);
			
			
			
		//	SendMessage(hDlg, WM_COMMAND, IDCANCEL, 0);
	
			
			

			imalloc->Free(pidl);
			imalloc->Release();
			

		}

		if((LOWORD(wParam))==IDCANCEL)
		{
			
			PostQuitMessage(0);
			
			EndDialog(hDlg,0);
		}
	}
			
	return 0;

}





extern "C" __declspec (dllexport) int DialogInvoke ( )
{
   DialogBox(ghInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,MainDlgProc);
   return 0;
}



//Main window
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
	//InitCommonControls();
	ghInstance=hInstance;
	//DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,MainDlgProc);
	//DialogInvoke ( ) ;
	return 0;
	
}




is this code a proper definition of the function i want to use?
C#
extern "C" __declspec (dllexport) int DialogInvoke ( )
{
   DialogBox(ghInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,MainDlgProc);
   return 0;
}

the problem is the dialog doesn't pop up from another project , but it's working fine by itself.
Posted

You need to add a DllMain function, as described in http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583(v=vs.85).aspx[^] to set the correct value in ghInstance. As it stands your call will fail because the system cannot find the dialog resource.
 
Share this answer
 
 
Share this answer
 
ok thanks i'll try,hope the reason lies there
 
Share this answer
 
i've added this code

C++
HINSTANCE g_hInst = 0;
 
BOOL WINAPI DllMain(HINSTANCE hInst, DWORD Reason, LPVOID Reserved)
{
    if (Reason == DLL_PROCESS_ATTACH)
        g_hInst = hInst;
    return TRUE;
}//DllMain


then calling the dll function like this :

Objective-C
typedef LRESULT (*DisplayMyMessage_pfn)(HWND) ;
    HMODULE hmod = LoadLibraryA("d:\\working BrowseForFolder\\BrowseForFolder\\release\\BrowseForFolder.dll");
   if (!hmod)
   {

        reportError ( "LoadLibrary failed" );
       return 1;
   }//if

   DisplayMyMessage_pfn dm =
       (DisplayMyMessage_pfn)GetProcAddress(hmod, "DialogInvoke");
   if (!dm)
   {
       FreeLibrary(hmod);

         reportError ( "GerProcAddress failed" );
       return 1;
   }//if

   dm(0);

   FreeLibrary(hmod);


also it seems i must declare the function like this

C++
extern "C" __declspec(dllimport) 
LRESULT DialogInvoke(HWND hwndOwner);

but then i'll receive the error saying u cant define the funtion
then how to define the fucntion?


here is the working project Customizing the "Browse for folder" dialog[^]

i would really appreciate any help
 
Share this answer
 

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