473,326 Members | 2,813 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.

dllmain

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 Framework Developer's Guide" it says that "...each
assembly can have only one entry point (that is, DllMain, WinMain, or
Main..."

So we've got "must" vs. "can" and "DLLMain" vs. "DllMain."

In playing with this, it doesn't appear to make any difference whether it's
included or not, or how it's spelled. It also never seems to get called
automatically upon loading. Since there aren't any variables living outside
of class scope in C#, it further seems that there wouldn't be much call (eh,
sorry) for DllMain anyway.

Can someone enlighten me as to the purpose and usage of DllMain in a pure
managed-code class library assembly? Is it possible to get it called
automatically when the assembly is loaded if one had reason to need such a
feature?

Thanks.

Michael Roper
Nov 15 '05 #1
4 10187
Hi Michael,

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 Framework Developer's Guide" it says that "...each
assembly can have only one entry point (that is, DllMain, WinMain, or
Main..."

So we've got "must" vs. "can" and "DLLMain" vs. "DllMain."

In playing with this, it doesn't appear to make any difference whether it's included or not, or how it's spelled. It also never seems to get called
automatically upon loading. Since there aren't any variables living outside of class scope in C#, it further seems that there wouldn't be much call (eh, sorry) for DllMain anyway.


The only entry point you really need is Main(). In C# this method is already
part of the application, in dll's it's not needed. In VB.NET, a sub "Main"
doesn't seem to exist but is created in IL-Code automatically. In managed
code dlls you don't need to specify an entry point.

Regards,

--
Frank Eller [.NET MVP]
www.frankeller.de
..NET Developers Group Munich- www.munichdot.net

Nov 15 '05 #2
Is this Mr. Liberty's book based on a beta version of the framework? Is that
quote from the MSDN a current one? If so, could you give us a link to the
online page? I suspect this is all based on a beta version of the framework.

Chris
Nov 15 '05 #3
Chris Capel writes:
Is this Mr. Liberty's book based on a beta version of the
framework?
3rd edition, (c) 2003. "Updated for .NET 1.1 & Visual Studio .NET 2003"
Is that quote from the MSDN a current one?
http://tinyurl.com/n64h
I suspect this is all based on a beta version of the framework.


Doesn't seem so.

So, is the answer to my question then, that DllMain is vestigial and has no
purpose in a managed class library? Is there ever a need to perform
initialization work when a library is loaded, and if so, how is that done in
the absence of DllMain?

Thanks again.

Michael Roper
Nov 15 '05 #4
> So, is the answer to my question then, that DllMain is vestigial and has
no
purpose in a managed class library? Is there ever a need to perform
initialization work when a library is loaded, and if so, how is that done in the absence of DllMain?


Don't know. I know that windows DLLs have a DLLMain (not sure about the
spelling) and that's called to initialize global variables when the library
is loaded using LoadLibrary or by other methods, but I'm not sure that any
of that is necessary in .NET. Perhaps if you're doing some advanced P/Invoke
in a .NET dll you'd need to do some of this, but I don't see why. It may be
more of a method to support a couple of necessary hacks here and there in
the framework itself to get a nice tight integration with the GUI or other
native code.

Chris
Nov 15 '05 #5

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

Similar topics

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
9
by: Ulrich Proeller | last post by:
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...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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

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.