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 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
"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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |