在vb6中,如何从C DLL获取char *参数? [英] in vb6, how do I retrieve a char* parameter from a C dll?

查看:371
本文介绍了在vb6中,如何从C DLL获取char *参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从我的VB6应用程序调用一个C DLL。 dll具有如下的函数调用签名。

  void WINAPI geterrstr(char * foo); 

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



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

  Declare Sub geterrstr Libtechnopnp.dll(ByRef lpbuffer As String)

任何想法?

解决方案

你应该可以;

 code> Declare Sub geterrstr Libtechnopnp.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 = )然后
//没有数据
else
如果

$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

n 需要适当的缓冲区大小,太短,会崩溃。


I am calling a C dll from my VB6 application. The dll has a function call signature as follows.

void WINAPI geterrstr(char* foo);

where foo is a string that has to be returned.

In my VB6 application, I have tried calling my dll by using the following syntax, but it returns an empty string.

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

Any ideas?

解决方案

You should be able to;

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 needs to be an appropriate buffer size, too short and it will crash.

这篇关于在vb6中,如何从C DLL获取char *参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆