Re: Detect if a DLL is an MFC Extension DLL

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 05/04/04


Date: Mon, 03 May 2004 21:40:17 -0400

One way is to rename all the functions, the same way Windows does.

Your ANSI version has all the entry points that require strings suffixed with A. Your
Unicode version has all the entry points that require strings suffxied with W.

Whether or not you think it makes sense to support both A and W at the same time is up to
you. But a bit of #ifdefing of the _UNICODE (or is it UNICODE...one is for Windows, the
other for the C library, and since you always have to set both, I never keep them
straight, but look in any of the base Windows header files to see which one they use) will
allow you to define macros, e.g.,

#ifdef _UNICODE
#define DoSomethingToThisString DoSomethingToThisStringW
#else
#define DoSomethingToThisString DoSomethingToThisStringA
#endif

int DoSomethingToThisString(LPTSTR p);

Then, at least, if they try to load the wrong DLL they won't be able to because the entry
points will mismatch. This would avoid at least some of the problems you anticipate.

As far as I know, there is no way to detect if a DLL is an MFC extension DLL from outside
the DLL, loaded or not. Nor would there be a way to detect if it is a Unicode version or
not, short of reading the PE format and looking for known calls that would call known
entry points with suffix-W or suffix-A names. Overall, better to just create DLLs with
different entry point names and avoid the problem.
                                joe

On Mon, 3 May 2004 14:36:03 -0700, Keith Brautigam <anonymous@discussions.microsoft.com>
wrote:

>My application can call customer-written code that they write in their own DLL to do their own custom processing.
>
>My app is an MFC app built with Service Pack 5 of Visual C++ 6. Right now it is a non-Unicode app.
>
>The next version, however, is going to be built for Unicode -- at least when installing on Windows 2000 and XP.
>
>The potential problem scenario is this: say a user is running my app, currently a non-Unicode app, on Windows 2000 or XP. And let's say they have their own custom code in a DLL, built as a non-Unicode MFC extension DLL. Now let's say the customer upgrades to the next version of my app. Now my app will be loading the Unicode version of MFC. However, their DLL could cause the non-Unicode version of MFC to be loaded. Mixing non-Unicode MFC and Unicode MFC in the same process seems to be a problem with MFC Extension DLLs.
>
>What I would like to do is to detect if their DLL is an MFC extension DLL. And I want to do the detection without ever having LoadLibrary or AfxLoadLibrary called on their DLL, because I don't want the mere loading of their DLL to cause the non-Unicode version of MFC to be loaded.
>
>Is there a way to detect if a DLL is an MFC extension DLL without loading the DLL?
>
>Thank you very much.

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


Quantcast