Link to home
Start Free TrialLog in
Avatar of fidodido
fidodido

asked on

UNICODE usage in MFC Ext DLL

Hi,

I have problem with UNICODE usage. The following is the scenarion. Its a bit lengthy but I have tried to put the question as clearly as possible.
 
I have a main application which allows me to load any DLL at runtime and call any exported function from the loaded DLL. The following thing should be noted.

1. Main application is build in non-UNICODE mode
2. The DLL that I am loading (the one giving the problem) is an MFC extension DLL and build in UNICODE mode. It has its own dialog resource and an exported funtion void TestFunc(void) coded as follows

TestFunc(void)
{
  //Get the current resource handle
  HINSTANCE hInstOld = AfxGetResourceHandle();
  //Set it to the extension DLL's resource handle
  AfxSetResourceHandle(TMyExtDLL.hModule);
            
 //Test dialog : the resource is in the ext DLL
 CMyDlg dlg;
 dlg.DoModal();

 //Restore the old resource handle
 AfxSetResourceHandle(hInstOld);
}

Now the problem:
1. I load the extension DLL in my application - Works Fine.
2. I call the exported funtion TestFunc - Fails.

The application crashes at this point. I have noted that AfxGetReourceHandle() & AfxGetCurrentInstance() fails which leads to the final crash.

But when my extension DLL is built in non-UNICODE mode, everything works fine !

What could be the problem ? Can't I mix unicode & non-unicode app & DLL like this ?

Thanks for your time
Prashanth
ASKER CERTIFIED SOLUTION
Avatar of Answers2000
Answers2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial