C# c中的DWORD和VARTYPE等价物#

C# c中的DWORD和VARTYPE等价物#,c#,c#-4.0,pinvoke,marshalling,C#,C# 4.0,Pinvoke,Marshalling,我使用的API包含以下方法: BOOL GetItemPropertyDescription (HANDLE hConnect, int PropertyIndex, DWORD *pPropertyID, VARTYPE *pVT, BYTE *pDescr, int BufSize); BOOL ReadPropertyValue (HANDLE hConnect, LPCSTR Itemname, DWORD PropertyID, VARIANT *pValue); c#中的等价物是什

我使用的API包含以下方法:

BOOL GetItemPropertyDescription (HANDLE hConnect, int PropertyIndex, DWORD *pPropertyID, VARTYPE *pVT, BYTE *pDescr, int BufSize);
BOOL ReadPropertyValue (HANDLE hConnect, LPCSTR Itemname, DWORD PropertyID, VARIANT *pValue);
c#中的等价物是什么


DWORD、VARTYPE、VARIANT
数据类型的含义是什么?

表1中有一个相当完整的表。试试看

DWORD is uint
VARTYPE is an ushort (but you have a ref ushort there) 
        or much better a VarEnum (but you have a ref VarEnum there)
        (VarEnum is defined under System.Runtime.InteropServices)
VARIANT is object (but you have a ref object there)
这里有一篇关于变量封送的文章:

精确的PInvoke编写起来很复杂,它取决于参数的方向和它们的精确规格。
pPropertyID
是指向单个
DWORD
的指针,还是指向“数组”的第一个
DWORD
的指针?谁“填充”指向的值,调用方或被调用方,或两者都是?所有其他指针也是如此

从技术上讲,如果被调用方填写了
ref
s的全部/部分内容,则可以
out

根据这些方法的名称,它们的pinvoke可能是:

[DllImport("YourDll.dll")]
//[return: MarshalAs(UnmanagedType.Bool)] // This line is optional, and it's implicit
bool GetItemPropertyDescription(IntPtr hConnect, 
                                int propertyIndex, 
                                out uint pPropertyID, 
                                out VarEnum pVT, 
                                out IntPtr pDescr, 
                                int bufSize);

[DllImport("YourDll.dll", CharSet = CharSet.Ansi)]
//[return: MarshalAs(UnmanagedType.Bool)] // This line is optional, and it's implicit
bool ReadPropertyValue(IntPtr hConnect, 
                       string itemName, 
                       uint propertyID, 
                       out object pValue);