Link to home
Start Free TrialLog in
Avatar of dancablam
dancablam

asked on

Visual C++ Compile Error: error LNK2005: _DllMain@12 already defined in DllMain.obj

I'm working on a DLL and now that I've included the MFC into my project I get the following error:

mfcs100.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in DllMain.obj

My understanding is that since I already have a DLLMain entry point in my DLL and the MFC has an entry point it creates a conflict. I can fix the issue by commenting out my DLLMain declaration but that's not desirable since I need to link to the process attach, thread attach, etc events.

I've read several of the MSDN articles but wasn't able to get any suggestions to work. Does anyone know how to make MFC coexist in a DLL project?

Thanks,
Dan
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

The MFC dll has an own structure. The MFC Dlls (mainly the CRT library) should be linked in a special order.
You can read and try the scenarios described here:
http://support.microsoft.com/kb/148652

You can simply delete your version of DLLMain.

I hope it will help. In case it does not, try the way I like and use all the time:

You can create new MFC DLL project aside. Better with the same name. Then, copy your files into this new project. Or accurately copy the project settings and the main h and cpp files from this new project to he existing one.
Avatar of dancablam
dancablam

ASKER

Deleting my DLLMain works but then how can I link in to the process attach and thread attach events without my own DLLMain?
Avatar of Pramod Bugudai
Thats why pgnatyuk has mentioned to create a MFC extension DLL. You can do these things i.e. thread attach etc. Try make your function and class exports from the MFC extension DLL.
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

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
initInstance looks like it will be a great solution. Thanks.