在vb6中,如何从C dll中检索char *参数?

时间:2011-11-12 18:14:26

标签: string dll vb6 function-calls

我从VB6应用程序调用C dll。 dll具有函数调用签名,如下所示。

void WINAPI geterrstr(char* foo);

其中foo是必须返回的字符串。

在我的VB6应用程序中,我尝试使用以下语法调用我的dll,但它返回一个空字符串。

Declare Sub geterrstr Lib "technopnp.dll" (ByRef lpbuffer As String)

有什么想法吗?

1 个答案:

答案 0 :(得分:5)

你应该能够;

Declare Sub geterrstr Lib "technopnp.dll" (ByVal lpbuffer As String)
...
dim buff as string
buff=string$(n, vbnullchar)
geterrstr buff

//read upto 1st vbnullchar
buff = left$(buff, instr(1, buff, vbnullchar) - 1)
if (buff="") then
  //no data
else
  msgbox buff
end if

n需要是一个合适的缓冲区大小,太短而且会崩溃。

相关问题