losingsleeep
losingsleeep

Reputation: 1879

How to use load and unload native DLL files in .NET Compact Framework?

I have a .NET Compact Framework (CF) application on Windows CE that interacts with native some DLL files, and the application has some unknown behaviors and problems.

For now, I'm using direct calls by using the [DllImport] attribute and define a method:

[DllImport("mynative.dll")]
private static extern void HelloWorld(byte[] arrName);

I want to try to release the loaded libraries, and web researches showed me LoadLibrary and FreeLibrary. How can I find a tutorial or sample code?

Stack Overflow question How to dynamically load and unload a native DLL file? is a desktop sample, but how can it done for Compact Framework? Note that .NET Compact Framework does not have Marshal.GetFunctionPointerForDelegate method.

Upvotes: 0

Views: 1617

Answers (1)

ctacke
ctacke

Reputation: 67168

The CF runtime itself calls LoadLibrary for P/Invokes - it calls it for every different "version" of the DLL you use (so if you used "mynative.dll" in one place and just "mydll" in another, it would get called twice).

The handle returned from that call is not exposed to applications, nor should it be. There is no way, short of closing the app, to get the runtime to call FreeLibrary on that DLL, so there is no way to release it.

I'm going to have to agree with @Cody Gray's comment on the question, though, in that even if it did work, it wouldn't fix the problem. You need to actually find and fix the bug causing the bad behavior you're seeing.

Upvotes: 1

Related Questions