vb调用vc写的dll, 关于字符指针传递的问题!!!急!! 请大家帮忙!!!!

shenzhenzyszd 2005-09-09 07:34:17
VC中是这么声明的:

#define VCVB_API extern"C" __declspec(dllexport)
VCVB_API void __stdcall VC2VB(char *pString)
{
pString = "china";
}

VB中是这样的:
Option Explicit
Private Declare Sub VC2VB Lib "vbvcdll.dll" (ByVal pString As String)

Private Sub Command1_Click()

Dim strSource As String
strSource = String(10, 0)

VC2VB strSource
Me.AutoRedraw = True
Print strSource '如果正确应该输出的是china

End Sub

但是结果总是不对, strSource 还是空的.
请问大家,这个是怎么回事? 请大家帮忙!
多谢!!!!!!!!!!!!!!!!!!!!!!!!!!!
...全文
187 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
DooDu 2005-09-10
  • 打赏
  • 举报
回复
Private Declare Sub VC2VB Lib "vbvcdll.dll" (byref pString As byte)
▲▲▲ ▲▲▲
sub abc
dim bytes() as byte
bytes(0)=&H12
bytes(1)=&HAA
call VC2VB(bytes(0))
end sub



对于vb这边,byte的指针就是这么传的。vc那边的函数声明还是*char
射天狼 2005-09-10
  • 打赏
  • 举报
回复
把这个
Private Declare Sub VC2VB Lib "vbvcdll.dll" (ByVal pString As String)
改成
Private Declare Sub VC2VB Lib "vbvcdll.dll" (ByRef pString As String)
试一下
supergreenbean 2005-09-09
  • 打赏
  • 举报
回复
c代码有问题,应该类似这样写
VCVB_API void __stdcall VC2VB(char *pString)
{
//pString = "china";
strcpy(pString,"china");
}

你的"china"常量在你调用函数完后就拜拜了,当然不会留下啥.
51365133 2005-09-09
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/4235/4235006.xml?temp=.8738062

到这里看看 就可以了

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧