从C ++ dll返回字符串到VB [英] return a string from c++ dll to VB
问题描述
亲爱的所有
如何从c ++ dll返回字符串到VB?
我想通过返回值而不是参数返回字符串.
谷歌搜索了很多次....但是我找不到解决方法.
这是我的示例代码,但是当调用function(testBSTR())时,
示例程序崩溃了.
怎么了?那可能吗?
= c ++ dll代码=
外部"C" __declspec(dllexport)BSTR __stdcall testBSTR(){
BSTR消息;
LPSTR szData ="abcd";
消息= SysAllocStringByteLen(szData,strlen(szData));
返回消息;
}
= VB代码=
私有声明函数testBSTR Lib"MFCDLLTest.dll"; ()作为字符串
--------------------------------------------------- ------------
将lpRet设置为字符串
lpRet = testBSTR()<-已崩溃!
MsgBox(lpRet)
在以下网址查看文章
http://support.microsoft.com/kb/187912/zh-CN >
再见.
Dear, all
How can I return a string from c++ dll to VB?
I want to return a string through return value, not param.
So many times, googling.... but i couldn't find the solution.
Here is my sample code, but when the function(testBSTR()) is called,
the sample program is crashed.
What is wrong? Is that possible way?
= c++ dll code =
extern "C" __declspec(dllexport) BSTR __stdcall testBSTR() {
BSTR Message;
LPSTR szData = "abcd";
Message = SysAllocStringByteLen (szData, strlen(szData));
return Message;
}
= VB code =
Private Declare Function testBSTR Lib "MFCDLLTest.dll" () As String
-----------------------------------------------------------
Dim lpRet As String
lpRet = testBSTR () <- is crashed!!
MsgBox(lpRet )
Take a look at the article at the following web address
http://support.microsoft.com/kb/187912/en-us
Bye.
这篇关于从C ++ dll返回字符串到VB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!