I developed a regular dll for my mfc app.Loading the dll using afxLoadLibrary and geting the function exported in the dll using GetProcAddress both worked well ,but i got an error 1814 when processing the CreateDialog function in the dll.In the msdn ,i got the idea that the dll used by mfc should add AFX_MANAGE_STATE(AfxGetStaticModuleState( )) at the begining of every function in the dll,but it didn't work.
There is a dialog template resource in the dll. I also tried AfxSetResourceHandle,but it didn'd work.
HMODULE exd = AfxLoadLibrary("exd.dll");
if( mem!=NULL ){
::AfxSetResourceHandle((HINSTANCE)exd);
MyPROC myproc = (MyPROC)::GetProcAddress(exd,"proc");
if( myproc!=NULL) {
(*myproc)(::GetModuleHandle(NULL),NULL);
}else{
MessageBox("Load Function error","Error",NULL);
}
}else{
MessageBox("Load Dll error","Error",NULL);
}
The Code in the dll:
extern "C" __declspec(dllexport) void proc(HINSTANCE hInstance = NULL ,HWND parent = NULL)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()); HINSTANCE hr = ::AfxFindResourceHandle(MAKEINTRESOURCE(IDD_MEMORYCORNER),RT_DIALOG); if( hr == NULL ){
MessageBox(NULL,"Find Resource Failed","DLL Error Code",NULL);
}else{
::AfxSetResourceHandle(hr); }
HWND hDlg = ::CreateDialog(hInstance,MAKEINTRESOURCE(IDD_MEMORYCORNER),parent,DlgProc); if( hDlg != NULL ){
ShowWindow(hDlg ,SW_NORMAL);
MSG msg;
while( GetMessage(&msg,hDlg ,NULL,NULL)){
::IsDialogMessage(hDlg ,&msg);
}
}
::itoa(::GetLastError(),membuf,10);
MessageBox(NULL,membuf,"DLL Error Code",NULL);
}
Anyone helps,thanks.