开发者

load/unload C dll with C# problems

I'm having problems with external native DLL.

I'm working on ASP.NET 1.1 web application and have this DLL which I load through DLLImport directives.

This is how I map DLL functions:

    [DllImport("somedllname",  CallingConvention=CallingConvention.StdCall)] 
    public static extern int function1(string lpFileName,string lpOwnerPw,string lpUserPw);

    [DllImport("somedllname",  CallingConvention=CallingConvention.StdCall)] 
    public static extern int function2(int nHandle);

I call 开发者_JS百科the dll methods and all works great, but I have problems with this DLL crashing my web site on some cases, so I would like an option to unload the dll after I use it.

I found a solution at this link, but I don't have 'UnmanagedFunctionPointer' attribute in .NET 1.1 available.

http://blogs.msdn.com/jonathanswift/archive/2006/10/03/Dynamically-calling-an-unmanaged-dll-from-.NET-_2800_C_23002900_.aspx

Is there a way I can achieve what this guy did with his example?


I'm not sure if there's an easier way, but you could always load in a dll that dynamically loads/unloads the other dll that is causing you problems.


Maybe you could wrap the dll with COM and then take advantage of the COM infrastructure to load and unload the DLL... You can then interact with the dll from it's Com Callable Wrapper which is generated when you add a reference to the COM dll. If you really want to get specific about when to unload, after getting a reference to the object, you can specifical call Marshal.ReleaseComObject to release it's reference.

For more information see here... COM Wrappers


For whom it may concern, I found the solution on the following link...

http://www.codeproject.com/KB/cs/dyninvok.aspx?fid=2892&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=3436363&fr=26#xx0xx

It takes a bit of assembler coding... and it WORKS:)))

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜