表 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
“数组”中第一个的指针?谁“填充”指向的值,调用者或被调用者或两者兼而有之?所有其他指针都相同。
从技术上讲,如果它们由被调用者填充,则 s 的全部/部分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);