Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

UNICODE usage in MFC Ext DLL

Posted on 1998-10-07
1
Medium Priority
?
617 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:fidodido
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
Answers2000 earned 200 total points
ID: 1323061
>> What could be the problem ? Can't I mix unicode & non-unicode app & DLL like this ?

1. You CAN mix Unicode and non-Unicode code in an app, but NOT in the way you are attempting to do.
2. The problem is that an MFC extension DLL is supposed to share the same copy of MFC as the EXE which it extends, BUT MFC is compiled differently for Unicode and non-Unicode (i.e. there are different MFC DLLs for Unicode and non-Unicode).  If you think about say the CString class, even for a moment, it should be obvious that a Unicode capable CString is different from a 8bit character set CString.

Here are some possible work rounds assuming you Code you app in MFC as non-Unicode

1. Create your DLL as Unicode, but do not use MFC.   Do not share MFC objects with the host app, instead only share Windows objects (e.g HWNDs instead of CWnds, etc).  In the DLL simply use API calls

2. Make your DLL into an OCX using Unicode.  An OCX has its own copy of MFC (you can't share MFC objects between app and the OCX)

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question