1

I must call C DLL with VB6.

C Code

short int decode(BOOL Mode, char* tete, char* adresse, char* status, char* nombre, char* datadecode);

My VB Code :

Private Declare Function decode Lib "VBdecode.dll" ( _ 
ByVal Mode As Long, _ 
ByVal tete As String, _ 
ByVal adresse As String, _ 
ByVal status As String, _ 
ByVal nombre As String, _ 
ByVal datadecode As String) As Long
Dim retour_lire As Long
Dim buffer(4) As Byte   
Dim  vbcData as string
Dim i As Integer
Dim chdecode As string

retour_lire = Byte_read(True, "4", "00", buffer, "16", vbcData)

For i = 1 To 10 
chdecode = vbcData(i) 
Next

MsgBox chdecode

but my VB6 code is not functional.

please any ideas, any proposals or corrections.

please help me, I count on you.

4

1 回答 1

1

评论实际上是错误的。你说的对。VB6 会将Strings (无论如何以这种方式发送)转换为char*. 如果您正在使用VarPtr()或使用As Any,他们将是正确的。

你的问题是返回值。short int在 C++ 端更改为或intAs LongVB6 端更改为As Integer.

所以要么:

int decode(BOOL Mode, char* tete, char* adresse, char* status, char* nombre, char* datadecode);

或者:

Private Declare Function decode Lib "VBdecode.dll" ( _ 
ByVal Mode As Long, _ 
ByVal tete As String, _ 
ByVal adresse As String, _ 
ByVal status As String, _ 
ByVal nombre As String, _ 
ByVal datadecode As String) As Integer

不是都 :)!

值得注意的是,您的示例代码实际上并没有调用decode(). 所以另一个问题,这只是一个猜测,是你试图在 C++ 端更改字符串的内容。您可以更改字符串,但不能重新分配它。所以你需要有它的大小(使用Space$())。

于 2013-09-02T12:06:23.503 回答