Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C PINVOKE查询(无符号长*)_C_C# 4.0_Pinvoke - Fatal编程技术网

C PINVOKE查询(无符号长*)

C PINVOKE查询(无符号长*),c,c#-4.0,pinvoke,C,C# 4.0,Pinvoke,我试图调用一个C函数,该函数将以下结构作为参数: typedef struct CSTRUCT { unsigned long* p1; unsigned long* p2; unsigned long* p3; unsigned long* p4; } CSTRUCT; 我需要从C#调用函数,并且需要知道这个C结构的pinvoke C#等价物。有人能帮忙吗?C中的unsigned long*p1只是一个指针,通常在C#中声明为IntPtr。这是过程中最简单的部

我试图调用一个C函数,该函数将以下结构作为参数:

typedef struct CSTRUCT
{
    unsigned long* p1;
    unsigned long* p2;
    unsigned long* p3;
    unsigned long* p4;
} CSTRUCT;

我需要从C#调用函数,并且需要知道这个C结构的pinvoke C#等价物。有人能帮忙吗?

C中的unsigned long*p1
只是一个指针,通常在C#中声明为
IntPtr
。这是过程中最简单的部分。困难的部分是如何分配给指针。指向内存的指针是否属于C代码?还是C代码拥有的内存?是谁写的,是C代码还是C#代码?您需要知道这些问题的答案,然后才能继续前进。

我发现一个有用的工具是p/Invoke签名生成器,它是免费提供的(通过MSDN杂志和)

它生成的c代码是:

[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct CSTRUCT {

    /// unsigned int*
    public System.IntPtr p1;

    /// unsigned int*
    public System.IntPtr p2;

    /// unsigned int*
    public System.IntPtr p3;

    /// unsigned int*
    public System.IntPtr p4;
}