473,408 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,408 software developers and data experts.

DLLMain in assemblies?

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
Nov 21 '05 #1
3 3068
It's not something that you want to us e in managed code.

MSDN says:
DllMain
The DllMain function is a user defined entry point for a DLL. Unless the
user specifies otherwise, DllMain is invoked every time a process or thread
attaches to or detaches from the containing DLL. Since this invocation can
occur while the loader lock is held, no user-supplied DllMain function
should be compiled to MSIL. Furthermore, no function in the call tree rooted
at DllMain can be compiled to MSIL. To resolve issues here, the code block
that defines DllMain should be modified with #pragma unmanaged, or the
object file containing DllMain should be compiled without the CLR switch.
The same should be done for every function that DllMain calls.

see http://msdn2.microsoft.com/library/m...us,vs.80).aspx
"Jozsef Bekes" <bj****@hotmail.com> wrote in message
news:u5****************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #2


"Jozsef Bekes" wrote:
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


When you create a new instance of ANY class, the Public Sub New() gets
called. You can override this if needed. You can also implement IDisposable
to call the Dispose() method of your class to tear things down. As far as
one all inclusive method for the entire DLL, there is none. The reason
being, I would suspect, is because DllMain get's called mainly in a Dll
exposing API methods, in which the whole Dll is acted apon, whereas in .NET,
the entire Assambly is loaded, but only the specific class/object you call is
initiated.
o, in closing, put a Sub New() in all your classes, and maybe look into
IDisposable to make your Dll really able to take care of it's resources.

HTH,
Jody
Nov 21 '05 #3
Hi Jody,

thank you for your answer. For solving the problem I chose to use singletons
instead of globals. If anyone has any better idea, please let me know.

Jozsi

"Jody" <Jo**@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...


"Jozsef Bekes" wrote:
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


When you create a new instance of ANY class, the Public Sub New() gets
called. You can override this if needed. You can also implement
IDisposable
to call the Dispose() method of your class to tear things down. As far as
one all inclusive method for the entire DLL, there is none. The reason
being, I would suspect, is because DllMain get's called mainly in a Dll
exposing API methods, in which the whole Dll is acted apon, whereas in
.NET,
the entire Assambly is loaded, but only the specific class/object you call
is
initiated.
o, in closing, put a Sub New() in all your classes, and maybe look into
IDisposable to make your Dll really able to take care of it's resources.

HTH,
Jody

Nov 21 '05 #4

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...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.