Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I initialize a managed C++/CLI DLL?

Tags:

dll

c++-cli

What is, or should I ask, is there, an equivalent to DllMain when creating a DLL using C++/CLI?

Are there any restrictions on what cannot be called from this initialization code?

like image 513
DanJ Avatar asked Mar 02 '23 03:03

DanJ


2 Answers

Dan: With respect to the loader lock, C++/CLI's delay load of the CLR and proper initialization for a mixed mode binary, I just posted yesterday on the subject here.

More or less, if you have a mixed mode binary, you must not cause any managed code to run while you are in DllMain().

like image 110
RandomNickName42 Avatar answered Mar 08 '23 10:03

RandomNickName42


Since .NET 2.0 you have a "module initializer". See here for more information on how that solves the loader lock problem and also here

For a direct answer to your question, this page quotes the standard which says: "There are no limitations on what code is permitted in a module initializer. Module initializers are permitted to run and call both managed and unmanaged code."

like image 35
Ben Voigt Avatar answered Mar 08 '23 11:03

Ben Voigt