我將'unmanaged c'代碼封送到下面給出的C#代碼中。如何在c#中訪問編組結構數據的編組指針?
[DllImport("ContainerDll.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr NodeSearch(IntPtr firstNode, string key);
IntPtr firstNode = IntPtr.Zero;
private void button4_Click(object sender, EventArgs e)
{
IntPtr ret = NodeSearch(firstNode, "key_string");
}
//NodeSearch method will be called which is present in 'ContainerDll.dll'
//pointer to structure will be returned.
//my c-structure contains these fields.
// typedef struct container
// {
// char Name[20];
// void *VoidData;
// struct container *Link;
// }
// Node;
現在,我的C#類型'IntPtr'類型的變量'ret'獲得了這個結構的指針。它具有從'NodeSearch'方法返回的地址。
如何在C#表單應用程序(也在控制檯應用程序中)訪問?
我想我不能這樣使用:ret->名稱[0],ret-> VoidData等
我是初學者!你可以請我嗎?
這個http://blogs.msdn.com/b/jaredpar/archive/2008/11/05/dereference-a-double-intptr.aspx – Adam
感謝您的答覆。這對我很有用。 – SHRI