c#中的DWORD和VARTYPE等效



我使用的是包含以下方法的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)

这里有一篇关于VARIANT的封送的文章:http://blogs.msdn.com/b/adam_nathan/archive/2003/04/24/56642.aspx

确切的PInvoke编写起来很复杂,这取决于参数的方向及其确切的规范。pPropertyID是指向单个DWORD的指针,还是指向"数组"的第一个DWORD的指针?谁来"填充"所指向的值,调用者还是被调用者,或者两者兼而有之?所有其他指针也是如此。

从技术上讲,如果ref的全部/部分由被调用者填充,则它们可以是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);

最新更新