-1

Prompt how I can implement analog standard procedure WINAPI DllMain environment. Net dynamic loading. Dll

BOOL WINAPI DllMain (     In HINSTANCE hinstDLL,     In DWORD fdwReason,     In LPVOID lpvReserved   );

I want to Have a method in your c# library that is executed when it is loaded?

  • 1
    The question is unclear. What do you want to do? Have a method in your c# library that is executed when it is loaded? Call the DllMain of another library from C#? – PMF Mar 10 '14 at 09:22
  • I want to Have a method in your c# library that is executed when it is loaded? – user3170341 Mar 10 '14 at 10:46
  • possible duplicate of [.Net: Running code when assembly is loaded](http://stackoverflow.com/questions/505237/net-running-code-when-assembly-is-loaded) – Hans Passant Mar 10 '14 at 12:14

1 Answers1

0

There's no direct equivalence to this, however, you can create a static class (or at least a static constructor to some class) that will be executed when the class is used first:

 public class MyLibraryFactory
 {
     static MyLibraryFactory()
     {
          // Add static initializer code here.
          // it will be called when the class is first referenced or used.
     }
 }

This constructor will be called before any other method using that class. There's no guarantee that it is the first thing that is called inside the library, but the compiler ensures that anything else that executes inside your library is independent of this class, so you won't notice the difference.

PMF
  • 14,535
  • 3
  • 23
  • 49