最近遇到了在 C# 中调用非托管 dll 的问题,集中在托管/非托管的内存控制部分。
用VC++ 6.0 写的 dll 中,要求调用方释放内存,并会释放掉传入的内存(这个大家应该不陌生吧)。
由于时间问题,不可能重写 dll 。因此对此进行了简单研究。
下面摘录相关的URL链接,具体情况待研究成果出来再慢慢写:
Call Unmanaged Code By Vyacheslav Biktagirov
http://www.csharphelp.com/archives/archive52.html
http://www.csharphelp.com/archives/archive63.html
http://en.csharp-online.net/Call_unmanaged_DLL_functions_and_control_the_marshaling_of_data
这里实际上就是个目录,包含了以下页面:
Marshaling Data with COM Interop : http://msdn.microsoft.com/en-us/library/9f9f3yxf.aspx
Copying and Pinning : http://msdn.microsoft.com/en-us/library/23acw07k.aspx
Buffers Sample : http://msdn.microsoft.com/en-us/library/x3txb6xc.aspx
Memory Management with the Interop Marshaler : http://msdn.microsoft.com/en-us/library/f1cf4kkz.aspx
Default Marshaling Behavior : http://msdn.microsoft.com/en-us/library/zah6xy75.aspx
另外还有如下页面:
http://forums.msdn.microsoft.com/zh-CN/csharpgeneral/thread/b5f2857d-6dd2-4888-9185-5597f83df610/
用VC++ 6.0 写的 dll 中,要求调用方释放内存,并会释放掉传入的内存(这个大家应该不陌生吧)。
由于时间问题,不可能重写 dll 。因此对此进行了简单研究。
下面摘录相关的URL链接,具体情况待研究成果出来再慢慢写:
Call Unmanaged Code By Vyacheslav Biktagirov
http://www.csharphelp.com/archives/archive52.html
http://www.csharphelp.com/archives/archive63.html
http://en.csharp-online.net/Call_unmanaged_DLL_functions_and_control_the_marshaling_of_data
这里实际上就是个目录,包含了以下页面:
Marshaling Data with COM Interop : http://msdn.microsoft.com/en-us/library/9f9f3yxf.aspx
Copying and Pinning : http://msdn.microsoft.com/en-us/library/23acw07k.aspx
Buffers Sample : http://msdn.microsoft.com/en-us/library/x3txb6xc.aspx
Memory Management with the Interop Marshaler : http://msdn.microsoft.com/en-us/library/f1cf4kkz.aspx
Default Marshaling Behavior : http://msdn.microsoft.com/en-us/library/zah6xy75.aspx
另外还有如下页面:
http://forums.msdn.microsoft.com/zh-CN/csharpgeneral/thread/b5f2857d-6dd2-4888-9185-5597f83df610/