From: BoHuang on
In my DLL I have a function that accepts a CWnd as paramter. Thus I have to
#include "afxwin.h".

Doing this results in:
fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll
version) requires MFC shared dll version. Please #define _AFXDLL or do not
use /MD[d]

So I #define _AFXDLL
But now I get linking error:
>mfcs90d.lib(dllmodul.obj) : error LNK2005: _DllMain(a)12 already defined in MSVCRTD.lib(dllmain.obj)

How do I get around this? Thanks
From: David Ching on
"BoHuang" <BoHuang(a)discussions.microsoft.com> wrote in message
news:2470FC2D-4C70-40F2-908E-F74DC031228A(a)microsoft.com...
> In my DLL I have a function that accepts a CWnd as paramter. Thus I have
> to
> #include "afxwin.h".
>
> Doing this results in:
> fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll
> version) requires MFC shared dll version. Please #define _AFXDLL or do not
> use /MD[d]
>
> So I #define _AFXDLL
> But now I get linking error:
>>mfcs90d.lib(dllmodul.obj) : error LNK2005: _DllMain(a)12 already defined in
>>MSVCRTD.lib(dllmain.obj)
>


It sounds like you need to build a "regular" MFC DLL which can consume MFC
classes like CWnd. (An "extension" MFC DLL lets you export classes derived
from MFC classes, but that doesn't sound like you are doing that.)

The easiest way to get a regular MFC DLL is to use the AppWizard to generate
you the project and then copy the files from your current project in there.
This will set the defines like _AFXDLL corrrectly as well as the compiler
switches, and generate correct entry point code.

-- David

From: Giovanni Dicanio on

"BoHuang" <BoHuang(a)discussions.microsoft.com> ha scritto nel messaggio
news:2470FC2D-4C70-40F2-908E-F74DC031228A(a)microsoft.com...
> In my DLL I have a function that accepts a CWnd as paramter. Thus I have
> to
> #include "afxwin.h".
>
> Doing this results in:
> fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll
> version) requires MFC shared dll version. Please #define _AFXDLL or do not
> use /MD[d]
>
> So I #define _AFXDLL
> But now I get linking error:
>>mfcs90d.lib(dllmodul.obj) : error LNK2005: _DllMain(a)12 already defined in
>>MSVCRTD.lib(dllmain.obj)
>
> How do I get around this? Thanks

First, I think that David's answer is the correct thing to do: just let the
wizard create the "infrastructure" (skeleton) of your project, with proper
preprocessor definitions, etc.

However, I'm curious: what kind of CRT linking are you using?

Probably, you should make sure that both your MFC EXE and your MFC DLL are
using the *dynamic* linking to CRT, so you should open the project
Properties dialog box for both your MFC EXE and MFC DLL, and go to |
Properties | Configuration Properties | C/C++ | Code Generation, and check
the 'Runtime library' settings.

Make sure that for both the EXE and the DLL you have 'Multi-threaded DLL'
selected for Release builds, and 'Multi-threaded Debug DLL' selected for
Debug build.

(This is for VS2008, at least - I don't have older IDEs here to give proper
menu path, but it should be similar, at least for VS2005.)

HTH,
Giovanni