|
http://www.cnblogs.com/gakusei/archive/2008/12/17/1356892.html
1.对于字符串,如果是LPCTSTR ,就用byval !否则只可能是CString,这种类型VB无法处理!另外,VC中也没有string类型
2.对于VB系统有定义的类型[in],如果API中是指针就用?如IStream* stream,ByVal stream As IUnknown
3.对于VB系统有定义的类型,如Stream\ Image [in],如果API中不是指针,
4.对于VB系统无定义的类型[in],如果API中是指针就用byref ,如LPRECT lpRect 定义为 byref lpRect As RECT 或者byval varptr(RECT) as long
5.对于VB系统无定义的类型[in],如果API中不是指针,就只要保证在VB的声明中两参数实际长度一致即可(不要求保证个数一样,因为对于自定义数据类型要求引用传递)如:
BOOL PtInRect(CONST RECT *lprc, POINT pt)
Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
下面的也可以:
Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
Declare Function PtInRect Lib "user32" (ByVal lprc As Long, ByVal x As Long, ByVal y As Long) As Long
Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal cur As Currency) As Long
Declare Function PtInRect Lib "user32" (ByVal lprc As Long, ByVal cur As Currency) As Long
Declare Function PtInRect Lib "user32" (ByVal cur As Currency, ByVal x As Long) As Long
6.对于返回的指针,不管哪一种类型都用Long即可,如果返回其它结构体类型呢?
7.对于在参数中返回值的,一律不可定主为byval ,如果返回的是指针\双指针\句柄[out] ,一律定义为byref *** as long,
VB系统无定义的类型: 可以用public type - --- -- end type 来定义! 如果是C++中类的,则VB中无能为力。
通过组用获取的类 类型,可以作为VB系统自定义数据类型!
GdipLoadImageFromStreamICM(IStream* stream, GpImage **image); //假设这两个都是[in]参数!
Public Declare Function GdipLoadImageFromStream Lib "gdiplus" (ByVal stream As Long, image As Long) As GpStatus
image 是GpImage *类型指针的值 ,指向GpImage 。stream 是指针,指向IStream对象
Public Declare Function GdipLoadImageFromStream Lib "gdiplus" (Byref stream As IStream,byval image As Long) As GpStatus
image 是GpImage **类型指针的值,指向GpImage * 。stream 是IStream对象
Public Declare Function GdipLoadImageFromStream Lib "gdiplus" (Byref stream As IStream, image As GpImage *) As GpStatus '实际 是不可能的,只是用来说明道理
image 是GpImage *类型,经过byref后变成GpImage **类型了
Public Declare Function GdipLoadImageFromStream Lib "gdiplus" (Byref stream As IStream, byval image As GpImage **) As GpStatus '实际 是不可能的,只是用来说明道理
image 是GpImage **类型,由于 类型已经是对的了,就以必须byval!
指针,可以先获取好用byval隐式传递,或者直接用byref 变量显式传递,但是两者传给API的指针所指向的内容类型都是API想要的 |
|