Ada*_*oll 2 c# unmanaged visual-studio-2010
我正在研究自定义调试引擎,当我将我的结构编组到IntPtrVisual Studio崩溃时(正在调试的那个崩溃而不是调试器).
我的结构只不过是:
public struct DocumentContext : IDebugDocumentContext2, IDebugCodeContext2
{
private string _fileName;
//.....Implementation of interfaces
}
Run Code Online (Sandbox Code Playgroud)
我的编组代码如下所示:
var documentContext = new DocumentContext(_node.FileName);
var size = Marshal.SizeOf(documentContext);
IntPtr ptrDocContext = Marshal.AllocHGlobal(size);
//This is what is crashing
//I don't have a chance to catch anything, it just craps out
//Event log says faulting dll is nt.dll
Marshal.StructureToPtr(documentContext, ptrDocContext, true);
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
如果以前从未分配过非托管结构,则不应使用deleteOld.deleteOld仅在您覆盖以前的结构时才适用(例如,为了解除分配字符串引用).这应该有效:
Marshal.StructureToPtr(documentContext, ptrDocContext, false);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1627 次 |
| 最近记录: |