我写了个动态库
.h文件内容
#ifndef LIB_H
#define LIB_H
extern "C" char __declspec(dllexport)wordtohex(char strbuf[512],int pos);
#endif
.cpp文件大概内容
#include <iostream>
#include "lib.h"
using namespace std;
char wordtohex(char strbuf[512],int pos)
{ ……
……
……
return result[pos],pos;
}
在VB中写的Function如下
Declare Function wordtohex Lib "dllpublic.dll" (ByVal strc As String, ByVal pos As Integer) As String调用时的代码如下:
Dim a, d As Integer
Dim b, c As String
c = Trim(txtId.Text)
b = wordtohex(c, a)
信息错误提示为 DLL调用约定出错
.h文件内容
#ifndef LIB_H
#define LIB_H
extern "C" char __declspec(dllexport)wordtohex(char strbuf[512],int pos);
#endif
.cpp文件大概内容
#include <iostream>
#include "lib.h"
using namespace std;
char wordtohex(char strbuf[512],int pos)
{ ……
……
……
return result[pos],pos;
}
在VB中写的Function如下
Declare Function wordtohex Lib "dllpublic.dll" (ByVal strc As String, ByVal pos As Integer) As String调用时的代码如下:
Dim a, d As Integer
Dim b, c As String
c = Trim(txtId.Text)
b = wordtohex(c, a)
信息错误提示为 DLL调用约定出错
Dim b, c As String
Dim sTemp As StringsTemp = Trim(txtId.Text)
'要确保字符串c的长度为512
c = Left(sTemp, 512) & String((512 - Len(sTemp)), vbNullChar)
b = wordtohex(c, a)