简体   繁体   English

加载/卸载带有C#问题的C dll

[英]load/unload C dll with C# problems

I'm having problems with external native DLL. 我在使用外部本机DLL时遇到问题。

I'm working on ASP.NET 1.1 web application and have this DLL which I load through DLLImport directives. 我正在使用ASP.NET 1.1 Web应用程序,并且具有通过DLLImport指令加载的此DLL。

This is how I map DLL functions: 这就是我映射DLL函数的方式:

    [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 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. 我调用了dll方法,并且一切正常,但是在某些情况下,此DLL使我的网站崩溃时,我遇到了问题,因此,我想选择一个在使用dll后将其卸载的选项。

I found a solution at this link, but I don't have 'UnmanagedFunctionPointer' attribute in .NET 1.1 available. 我在此链接上找到了一个解决方案,但是.NET 1.1中没有可用的'UnmanagedFunctionPointer'属性。

http://blogs.msdn.com/jonathanswift/archive/2006/10/03/Dynamically-calling-an-unmanaged-dll-from-.NET-_2800_C_23002900_.aspx 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? 有什么方法可以实现我的榜样吗?

我不确定是否有更简单的方法,但是您始终可以加载一个动态加载/卸载另一个引起问题的dll的dll。

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. 也许您可以用COM包装dll,然后利用COM基础结构来加载和卸载DLL ...然后,您可以从DLL的Com Callable Wrapper中与dll进行交互,当您添加对COM dll的引用时,就会生成该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. 如果您真的想具体说明何时卸载,则可以在获取对该对象的引用之后,具体调用Marshal.ReleaseComObject释放其引用。

For more information see here... COM Wrappers 有关更多信息,请参见此处。COM包装器

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 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:))) 它需要一些汇编代码...并且可以工作:)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM