473,326 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

No DllMain() in MfcAtl project?

I currently hunting a problem with a MixedMode dll, which used to work well,
until the .NET Framework 2.0 is installed on a machine. Since the, the dll
fail when loaded stating that there is a problem with the "LoaderLock" bug.
Thus, I made sure that the dll is initialized properly before any other call
into the dll is made. I also gave my dll a empty DllMain as it was proposed
by Microsoft.

BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpvReserved)
{
return TRUE;
}

Since then, I get a Linker error:

mfcs71d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in
TwStratus.obj
mfcs71d.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in
TwStratus.obj; second definition ignored

When I try to prevent linking with <mfcs71d.lib>, I get the following
undefined symbols:

LINK : error LNK2020: unresolved token (0A000110) atlTraceException
LINK : error LNK2020: unresolved token (0A000111) ?s_trace@CTrace@ATL@@2V12@A

I don't know how to go on. Can anyone help me?
If this is the wrong group for this problem, please let me know!

Thanks in advance

Ulrich
Jan 29 '06 #1
9 3578
Hi Ulrich!
mfcs71d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in
TwStratus.obj


Either you use MFC or not...
If you use MFC, then the MFC provides a DllMain.

If you don´t use the MFC, you can define your own DllMain (and must not
call any managed code).

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Jan 29 '06 #2
Hello Jochen,

thanks for your reply!
What does that mean to me:
- Is it OK to use MFC in a mixed-mode (managed and unmanaged code) dll with
respect to the loader-lock problem?
- Or does that mean, that is is not possible to build mixed-mode DLLs in
conjunction with MFC?

What I am observing is: When I link my DLL (a TWAIN driver) with
mfcs71d.lib, the calling application terminates without any error message
when making a first call into that dll. When I try to set a breakpoint at the
first line of the entry point function, Visual Studio terminates with an
internal error.

DLL and calling application is compiled with VS 2003 and .NET Framework 1.1,
but the .NET Framework 2.0 is also installed on the machine and I can see in
the debugger, that some .NET 2.0 dll are loaded by the calling application
during startup.

Thanks for any idea.

Ulrich
Jan 30 '06 #3
Hi Ulrich!
- Is it OK to use MFC in a mixed-mode (managed and unmanaged code) dll with
respect to the loader-lock problem?
Normally it should be ok...

DLL and calling application is compiled with VS 2003 and .NET Framework 1.1,
but the .NET Framework 2.0 is also installed on the machine and I can see in
the debugger, that some .NET 2.0 dll are loaded by the calling application
during startup.


This is not good....
It seems that the app is loading the .NET 2.0 framework into the
process. And your DLLs is using the version 1.1.
The main problem of .NET is, that it is not possible to load two
runtime-version into one process. So your DLL must be able to run with
the v2 of .NET.
And it seems that MFC7.1 had some problem in mixed-mode DLLs run against
v2.0 of the framework...

I will try to reproduce the problem; maybe I can give you more infos...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Jan 30 '06 #4
Hi Jochen,

thanks for the quick response.
Let me know if I can give you any more information.

Ulrich

Jan 30 '06 #5
In addition to Jochen's reply...
What I am observing is: When I link my DLL (a TWAIN driver) with
mfcs71d.lib, the calling application terminates without any error message
when making a first call into that dll. When I try to set a breakpoint at the
first line of the entry point function, Visual Studio terminates with an
internal error.

DLL and calling application is compiled with VS 2003 and .NET Framework 1.1,
but the .NET Framework 2.0 is also installed on the machine and I can see in
the debugger, that some .NET 2.0 dll are loaded by the calling application
during startup.


Visual Studio 2003 (in managed or mixed debugger mode) cannot debug applications
that load CLR 2.0, internal error is a typical symptom of this problem.
If you want to debug the application with VS2003, configure it (the application)
to use CLR 1.1:

http://blogs.msdn.com/jmstall/archiv...with_2005.aspx

Regards,
Oleg
[VC++ MVP http://www.debuginfo.com/]

Jan 30 '06 #6
Hello Oleg,
Visual Studio 2003 (in managed or mixed debugger mode) cannot debug applications
that load CLR 2.0, internal error is a typical symptom of this problem.


Thanks a lot! This is very helpful to me! I will try to configure my dll to
use the 1.1 framework.

Kind Regards

Ulrich
Jan 30 '06 #7
Hi Ulrich!
Visual Studio 2003 (in managed or mixed debugger mode) cannot debug applications
that load CLR 2.0, internal error is a typical symptom of this problem.


Thanks a lot! This is very helpful to me! I will try to configure my dll to
use the 1.1 framework.


You can´t configure your DLL to use the v1.1!!!
You must configure the EXE to use v1.1!!! (which might be fail)
Of course, it is a very bad idea to create DLLs which only exposes
unmanaged functions and internaly uses dotNet...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Jan 30 '06 #8
Hello Jochen,
Of course, it is a very bad idea to create DLLs which only exposes
unmanaged functions and internaly uses dotNet...


I'm afraid you are right, but we had no choice: We produce an imaging
device, our internal software is all .NET based and we have to provide a
TWAIN driver to allow the outer world to access our device.
And a TWAIN driver is nothing more than a simple dll with only one(!) native
C entry point.
All this worked fine until the .NET 2.0 framework was installed on a target
machine. And now, I have to figure out way out of this mess.

Thanks for your help and if you have any idea, let me know!

Greetings

Ulrich
Jan 30 '06 #9
Hi Ulrich!
All this worked fine until the .NET 2.0 framework was installed on a target
machine. And now, I have to figure out way out of this mess.


I doubt you will solve this problem... ;-(
--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Jan 30 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Roper | last post by:
In Jesse Liberty's "Programming in C#" he says that "...an assembly must have exactly one entry point: DLLMain, WinMain, or Main. DLLMain is the entry point for DLLs..." In the MSDN ".Net...
0
by: Arno Huetter | last post by:
Hi there, I invoke a native DLL function from managed code. This works fine, but it seems that the DLL's DllMain function is never called upon attaching / detaching. Does anyone have an idea why...
7
by: Adam | last post by:
I have a managed cpp wrapper. Im using this in a native dll as a static variable. I need to free this library when the dll is done being used. The perfect place to do this is DllMain for...
3
by: Jozsef Bekes | last post by:
Hi All, is there a mechanism just like DllMain in VC6, a function that gets called whenever an assembly gets loaded? Thank you for all answers. Jozsi
2
by: Vincent Fatica | last post by:
I can get Explorer to load (via LoadLibrary()) my DLL using VirtualAlloc(), WriteProcessMemory(), and CreateRemoteThread() (a technique discussed here occasionally). But I'd really like to...
1
by: =?Utf-8?B?U2VhbiBDb25uZXJ5?= | last post by:
Hi, Is it possible to define DllMain in a static library for use in dlls? The reason is that I am defining a platform abstraction for being loaded as a shared library and I figured the simplest...
3
by: Abubakar | last post by:
Hi, I have a dll that gets called by an exe, I just placed a little code in its dlmain method and put a breakpoint on the code only to discover that its getting called nearly hundreds of times. I...
10
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, From MSDN, http://msdn2.microsoft.com/en-us/library/ms682583.aspx parameter fdwReason of DllMain has four values, DLL_PROCESS_ATTACH
0
by: Question123 | last post by:
Hi I am developing windows c# application in which i have given reference of third party DLL. "Do not attempt to run managed code inside a DllMain or image initialization function since doing so...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.