Link to home
Start Free TrialLog in
Avatar of BlaM
BlaM

asked on

DLL with CString -> WINDOWS.H already included. MFC apps must not #include <windows.h>

I  want to set up a DLL project in Visual C++  and need to support CString. How do I do that?

The following code results in the expected error, that CString is unknown:

-----------
#include "stdafx.h"

BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) {
    CString test;
    return TRUE;
}
-----------

However, if I add...

-----------
#include <afx.h>
-----------

I get the message "fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>". How do I solve this problem?!?
SOLUTION
Avatar of Member_2_1001466
Member_2_1001466

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
Avatar of BlaM
BlaM

ASKER

I don't understand your hint... There was no such line at this moment. There's only a line "#include <windows.h>".

If I add your line after that one, I still receive the message that I'm not allowed to include windows.h again.
If I add it before "#include <windows.h>" or remove "#include <windows.h>" I get "_DllMain@12 already defined in VxSBEngine.obj"
ASKER CERTIFIED SOLUTION
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
Avatar of BlaM

ASKER

Nice. Thanks. That worked.
In the same sort of problem I am using COleDateTime class. When I include afxdisp.h in my cpp file I get error "WINDOWS.H already included...."
I tried to replace stdafx.h with ATL with MFC support generated file. Then I got error "_DllMain@12 already defined in VxSBEngine.obj"

Any hints??
I've got the same problem as vinodatal: "_DllMain@12 already defined  ... anybody else who has faced this problem and found a solution to it?
ok, I found the solution myself to my question, so to vinodatal: in your .cpp file, remove the "BOOL APIENTRY DllMain ..." function.  That solved the problem here.
Hi,

I am having a similar problem.

I need to use a class that was created using MFC (see http://www.codeproject.net/internet/sslsocket.asp) into my project which does NOT use MFC and needs windows.h instead.

I am getting the same error. Anyone knows of a workaround?

Thanks,
Greg.
Rick,
There was no DllMain in any of the CPP file. ??
What I got as a solution is to create an empty ATL project with MFC support and then added my project files there. That worked !!
Simply replacing the header "Stdafx.h" has not solved my problem.

Need to find out diff between project settings..
~Vinod