1

I read this one What is the DLL loading behavior when using DllImport[] in C#?, and it partially ask my question, still I'm in search of a more detailed answer. I know pretty well how dlls worked back in the days of C/C++ applications, now I'm trying to understand if what I've been tasked to do is feasible.

I've got an old c dll which I have to use in the context of a multi threaded C# environment. The dll is thought for a single thread environment, and its (170!!!) exported functions cover a wide kind of types (basic types, pointers of every kind, HWNDs, handles...)

What I'm trying to better understand is in which way a C# environment load a native/unmanaged dll: in a C application I'd be explicitly using LoadLibrary, thus knowing and having controll on when (and where, in which thread) the dll is loaded and unloaded; what happens in C#, instead?

Community
  • 1
  • 1
motoDrizzt
  • 1,082
  • 11
  • 23
  • I believe it's loaded on first usage, and unloaded on appdomain unload. – Lucas Trzesniewski Apr 06 '16 at 16:10
  • http://stackoverflow.com/questions/2445536/unload-a-dll-loaded-using-dllimport, http://stackoverflow.com/questions/13967448/reload-a-dll-which-has-been-imported-with-dllimport – CodeCaster Apr 06 '16 at 16:14
  • DLLs are still DLLs. The OS is what loads/unloads them and the same rules apply. – Panagiotis Kanavos Apr 06 '16 at 16:15
  • If you use PInvoke you must load each method explicitly. I assume that when your C# application finishes (the process), the dll's methods are unloaded. – Dan Apr 06 '16 at 16:30

0 Answers0