C#中的DWORD和VARTYPE等效 [英] DWORD and VARTYPE equivalent in c#

查看:321
本文介绍了C#中的DWORD和VARTYPE等效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using an API which contains following methods:

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#中什么是等效的?

What will be equivalent in c#?

DWORD, VARTYPE, VARIANT数据类型是什么意思?

What is the meaning of DWORD, VARTYPE, VARIANT datatypes?

推荐答案

有一个相当完整的表

There is a fairly complete table here at Table 1. Try looking.

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)

这里有一篇有关变种编组的文章: http://blogs.msdn.com/b/adam_nathan/archive/2003/04/24/56642.aspx

There is an article here on the marshaling of VARIANT: http://blogs.msdn.com/b/adam_nathan/archive/2003/04/24/56642.aspx

确切的PInvoke编写起来很复杂,它取决于参数的方向及其确切的规格. pPropertyID是指向单个DWORD的指针,还是指向数组"的第一个DWORD的指针?谁填充"了调用者或被调用者或两者所指向的值?其他所有指针都一样.

The exact PInvoke is complex to write, it depends on the direction of the parameters and their exact specification. Is pPropertyID a pointer to a single DWORD, or is a pointer to the first DWORD of an "array"? And who "fills" the value pointed at, the caller or the callee or both? The same for all the other pointers.

从技术上讲,如果ref的全部/部分由被叫方填补,则可以为out.

Technically all/part of the refs could be out if they are filled by the callee.

按方法的名称,它们的拼字可能是:

By the name of the methods, their pinvoke could be:

[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);

这篇关于C#中的DWORD和VARTYPE等效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆