首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

求VB 调用C++ DLL Char* 回到字符串,用Byte接收

2012-12-31 
求VB 调用C++ DLL Char* 返回字符串,用Byte接收 !C++ 原型: void _stdcalldAdd(int inputs,char*& outputs

求VB 调用C++ DLL Char* 返回字符串,用Byte接收 !
C++ 原型:
 void _stdcall  dAdd(int inputs,char*& outputs)
{   char sa[256];
  memset(sa,0,256);
  sprintf(sa,"%s","ABCDEFG");
if(inputs=1314)
{
    outputs=sa;
return ;
}
}

VB里声明:
 Private Declare Sub dAdd Lib "**Dll.dll" (ByVal inputs As Long, ByRef outputs As Byte)
 outputs  我希望用Byte来接收并转成字符串?请问该怎么写呀,求帮忙?
 


[解决办法]
LP类型的参数是可返回的。
看看下面这个API,本来是这样声明的:
Private Declare Function GetWindowsDirectory Lib "kernel32.dll" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

改成这样声明,还是可以得到正确结果的:
Option Explicit
Private Declare Function GetWindowsDirectory Lib "kernel32.dll" Alias "GetWindowsDirectoryA" (ByRef lpBuffer As Any, ByVal nSize As Long) As Long

Private Sub Command1_Click()
    Dim sWinDir(128) As Byte
    GetWindowsDirectory sWinDir(0), 128
    Debug.Print StrConv(sWinDir, vbUnicode)
End Sub

[解决办法]
c的代码写错了!!!!
要么void _stdcall dAdd(int inputs,char &outputs)
或者void _stdcall dAdd(int inputs,char* outputs)  (建议用这种)

因为char*已经代表地址了
char*&引用的的是字符串的地址,不是字符串 (作用类似于char**,不是VB能用的char*)

热点排行