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
#include<windows.h>
#include<windowsx.h>
#include<commctrl.h>
#include<shlobj.h>
#include "resource.h"
HWND hdialog;
HINSTANCE ghInstance;
HWND edit;
TCHAR FolderName[MAX_PATH];
TCHAR c[MAX_PATH];
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);
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;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
ghInstance=hInstance;
return 0;
}
is this code a proper definition of the function i want to use?
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.