开发者

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

开发者 https://www.devze.com 2023-03-28 04:35 出处:网络
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.

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 FreeLibra开发者_如何转开发ry. 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号