VB6中的C ++代码转换

时间:2014-12-01 20:06:15

标签: c++ visual-c++ dll vb6 call

我有一个C dll,我想在vb6中使用它,这里是C语法:

#ifndef _MSC_VER
typedef long long INT64T;
#else
typedef __int64 INT64T;
#endif

int Init(int opts, void *key, INT64T offs);

我已将其转换为VB6:

Public Declare Function Init Lib "x.dll" (ByVal opts As Integer, ByVal key As Long, ByVal offs As Currency)

并称之为:

Init 0, 0, 0

执行了部分功能,我发现了这个错误:

  

错误的DLL调用约定

请问你能告诉我这是什么问题吗? dll来自第三方dll所以我对此一无所知,

1 个答案:

答案 0 :(得分:0)

对于64位,你应该使用:

Type ULARGE_INTEGER
  LowPart As Long
  HighPart As Long
End Type

你的声明应该是这样的:

Public Declare Function Init Lib "x.dll" (ByVal opts As Long, ByVal key As Long, ByVal offs As ULARGE_INTEGER)

Public Declare Sub CopyMemory Lib "kernel32" (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)

现在进行转换:

获得ULARGE_INTEGER后,您可以将其翻译为Currency,如下所示:

' Copy int64 into the Currency data type
Dim curr as Currency
Dim int64 as ULARGE_INTEGER

' Copy ULARGE_INTEGER into the Currency data type
CopyMemory curr, int64, 8

' Multiply by 10000 to move Visual Basic decimal point to the end of the actual number
curr = curr * 10000

ULARGE_INTEGER遍历Currency

Dim curr as Currency
Dim int64 as ULARGE_INTEGER

' Devide by 10000 to move Visual Basic decimal point to original position
curr = curr * 0.00001       

' Copy Currency into the ULARGE_INTEGER data type
CopyMemory int64, curr, 8
相关问题