我必须用VB6调用call。
C代码
short int decode(BOOL Mode, char* tete, char* adresse, char* status, char* nombre, char* datadecode);我的VB代码:
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但是我的VB6代码不起作用。
请提出任何想法,任何建议或更正。
请帮帮我,我全靠你了。
发布于 2013-09-02 20:06:24
这些评论实际上是错误的。你是正确的。VB6会将Strings (无论如何都是这样发送的)转换为char*。如果您使用的是VarPtr()或As Any,那么它们将是正确的。
你的问题是返回值。将C++端的short int更改为int,或将VB6端的As Long更改为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$())。
https://stackoverflow.com/questions/18562873
复制相似问题