函数原形: int __stdcall Array(int *a,int num); 调用如下: Declare Function (ByRef SampleA() as Long, ByVal NumSam as Integer) as Integer你的那个函数调用应该是: Declare Function GetLVDTResponse(ByVal szCommand as String,ByVal nWaitTime as Long) as String
VB和VC的数据类型 由于VB与VC之间的数据类型没有相同的关键字,为了方便,下面列出常用数据类型在VC与VB中分别使用的关键字以及它们之间的对应关系:c中的数据类型 VB中的声明 结果 ATOM ByVal variable As Integer 结果为Integer 类型的表达式 BOOL ByVal variable As Boolean 结果为 Long 类型的表达式 BYTE ByVal variable As Byte 结果为 Byte 类型的表达式 CHAR ByVal variable As Byte 结果为 Byte 类型的表达式 COLORREF ByVal variable As Long 结果为 Long 类型的表达式 DWORD ByVal variable As Long 结果为 Long 类型的表达式 HWND, HDC, HMENU ByVal variable As Long 结果为 Long 类型的表达式等Windows 句柄 INT, UINT ByVal variable As Long 结果为 Long 类型的表达式 LONG ByVal variable As Long 结果为 Long 类型的表达式 LPARAM ByVal variable As Long 结果为 Long 类型的表达式 LPDWORD variable As Long 结果为 Long 类型的表达式 LPINT, LPUINT variable As Long 结果为 Long 类型的表达式 LPRECT variable As type 自定义类型的任意变量 LPSTR, LPCSTR ByVal variable As String 结果为 String 类型的表达式 LPVOID variable As Any 任何变量(在传递字符串的时候使用ByVal) LPWORD variable As Integer 结果为Integer 类型的表达式 LRESULT ByVal variable As Long 结果为 Long 类型的表达式 NULL As Any 或 ByVal Nothing 或 ByVal variable As Long ByVal 0& 或 VBNullString SHORT ByVal variable As Integer 结果为Integer 类型的表达式 VOID Sub procedure 不可用 WORD ByVal variable As Integer 结果为Integer 类型的表达式 WPARAM ByVal variable As Long 结果为 Long 类型的表达式 ----------------------------------------------------------------------------------- 楼主给分哦~~
char* GetLVDTResponse(char* szCommand,long nWaitTime)-->Declare Function GetLVDTResponse(ByVal szCommand as String,ByVal nWaitTime as Long) As Long
declare: Declare Function GetLVDTResponse(ByVal lgCommand as long,ByVal nWaitTime as Long) As Long call: x=GetLVDTResponse(varptr(szCommand),nWaitTime)
Declare Function GetLVDTResponse(ByVal lgCommand as long,ByVal nWaitTime as Long) As Long 如果这样声明的话,得到一个长整形的返回值,没法把它当字符串用,要额外的作些处理才行。我建议用这种方法: declare: Declare Function GetLVDTResponse(ByVal lgCommand as long,ByVal nWaitTime as Long) As Long call: x=GetLVDTResponse(strptr(szCommand),nWaitTime) dim s as string s=vbnullstring copymemory byval varptr(s),x,4 msgbox s copymemory byval varptr(s),0&,4
Declare Function GetLVDTResponse(ByVal szCommand as String,ByVal nWaitTime as Long) as String调用前要先配空间比如 dim szCommand as string * 200
int __stdcall Array(int *a,int num);
调用如下:
Declare Function (ByRef SampleA() as Long, ByVal NumSam as Integer) as Integer你的那个函数调用应该是:
Declare Function GetLVDTResponse(ByVal szCommand as String,ByVal nWaitTime as Long) as String
由于VB与VC之间的数据类型没有相同的关键字,为了方便,下面列出常用数据类型在VC与VB中分别使用的关键字以及它们之间的对应关系:c中的数据类型 VB中的声明 结果
ATOM ByVal variable As Integer 结果为Integer 类型的表达式
BOOL ByVal variable As Boolean 结果为 Long 类型的表达式
BYTE ByVal variable As Byte 结果为 Byte 类型的表达式
CHAR ByVal variable As Byte 结果为 Byte 类型的表达式
COLORREF ByVal variable As Long 结果为 Long 类型的表达式
DWORD ByVal variable As Long 结果为 Long 类型的表达式
HWND, HDC, HMENU ByVal variable As Long 结果为 Long 类型的表达式等Windows 句柄
INT, UINT ByVal variable As Long 结果为 Long 类型的表达式
LONG ByVal variable As Long 结果为 Long 类型的表达式
LPARAM ByVal variable As Long 结果为 Long 类型的表达式
LPDWORD variable As Long 结果为 Long 类型的表达式
LPINT, LPUINT variable As Long 结果为 Long 类型的表达式
LPRECT variable As type 自定义类型的任意变量
LPSTR, LPCSTR ByVal variable As String 结果为 String 类型的表达式
LPVOID variable As Any 任何变量(在传递字符串的时候使用ByVal)
LPWORD variable As Integer 结果为Integer 类型的表达式
LRESULT ByVal variable As Long 结果为 Long 类型的表达式
NULL As Any 或 ByVal Nothing 或 ByVal variable As Long ByVal 0& 或 VBNullString
SHORT ByVal variable As Integer 结果为Integer 类型的表达式
VOID Sub procedure 不可用
WORD ByVal variable As Integer 结果为Integer 类型的表达式
WPARAM ByVal variable As Long 结果为 Long 类型的表达式
-----------------------------------------------------------------------------------
楼主给分哦~~
能够得到返回值吗?现在传进参数是没有问题了,但是得不到返回值?咋回事?
Declare Function GetLVDTResponse(ByVal lgCommand as long,ByVal nWaitTime as Long) As Long
call:
x=GetLVDTResponse(varptr(szCommand),nWaitTime)
如果这样声明的话,得到一个长整形的返回值,没法把它当字符串用,要额外的作些处理才行。我建议用这种方法:
declare:
Declare Function GetLVDTResponse(ByVal lgCommand as long,ByVal nWaitTime as Long) As Long
call:
x=GetLVDTResponse(strptr(szCommand),nWaitTime)
dim s as string
s=vbnullstring
copymemory byval varptr(s),x,4
msgbox s
copymemory byval varptr(s),0&,4
dim szCommand as string * 200