请问VC中写的Dll用于VB中调用,其中要传递一个字符串,应该怎么写???? 用地址传递的方法,试一下VB里的AddressOf str,得到str的地址,然后把这个地址传给MyFun函数。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 freeghost(星子)谢谢你的回复。但我是要问在VC中怎么写MyFun(),谢谢。 我知道要用到什么 BSTR ,LPCTSTR之类的,但具体怎么用法不太清楚,还请高手指点一二。 你在VB中定义这个dll函数的时候用ByRef型的,在VC中用LPSTR或char *这两个是相同的,如果用LPCTSTR我想不行吧,但也不敢确定我也没试过。 freeghost(星子):理论上我也知道一点点,但在实际操作中不行:大家看我写的这个有没有问题:#include <comutil.h>extern "C" BSTR _stdcall MyFun(BSTR str){ CString str; str=_com_util::ConvertBSTRToString(str); str+="Hello,World!"; return _com_util::ConvertStringToBSTR(str);}这样写的错误很多啊,请问应该怎么改? 程序是这样写,编译时会出现:extern "C" BSTR _stdcall MyFun(BSTR str){ CString cstr; cstr=_com_util::ConvertBSTRToString(str); cstr+="Hello,World!"; return _com_util::ConvertStringToBSTR(cstr);}Linking... Creating library Debug/dll.lib and object Debug/dll.expdll.obj : error LNK2001: unresolved external symbol "unsigned short * __stdcall _com_util::ConvertStringToBSTR(char const *)" (?ConvertStringToBSTR@_com_util@@YGPAGPBD@Z)dll.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z)Debug/dll.dll : fatal error LNK1120: 2 unresolved externalsError executing link.exe.dll.dll - 3 error(s), 0 warning(s)这些是什么错误? 你试一下把前边的extern "C" 去掉然后再试一下呢? 请在函数开头加USES_CONVERSION;extern "C" BSTR _stdcall MyFun(BSTR str){ USES_CONVERSION; LPTSTR x = OLE2T(str);} 你如此声明函数:TYPE_declspec(dllexport) MyFun(BSTR str){ ... ...}其中,大写的TYPE表示是函数的类型,可以是各种类型的,如:void,int 等! 去掉对_com_util::ConvertStringToBSTR函数的引用,改用#include <comdef.h>extern "C" BSTR _stdcall MyFun(BSTR str){ _bstr_t bstrTemp(str, true); bstrTemp += "hello, world"; return SysAllocString(bstrTemp);} 怎么把一个结构读写到文件里 使用libnids出现问题,连接库错误? 本科明年毕业,想从事游戏事业,正在学D3D,达到什么水平能够找一个比较好的工作啊? 如何在vc下连接一个.asm文件? 请问我这么做,为什么不好用? 怎么让slider的滑块停在中间??在线... 奇怪,如何带缺省的参数呢? 如何让MFC程序不在任务管理器的“应用程序”栏显示 只有40分了!我快疯了:怎样在Access中查询一个COleDateTime类型的记录?请看一下我的源代码。请各位好心人帮帮忙,谢谢 C++实现炮弹飞行轨迹 一闪一闪亮晶晶?! CListCtrl很简单的问题。。送分。。
#include <comutil.h>
extern "C" BSTR _stdcall MyFun(BSTR str)
{
CString str;
str=_com_util::ConvertBSTRToString(str);
str+="Hello,World!";
return _com_util::ConvertStringToBSTR(str);
}这样写的错误很多啊,请问应该怎么改?
extern "C" BSTR _stdcall MyFun(BSTR str)
{
CString cstr;
cstr=_com_util::ConvertBSTRToString(str);
cstr+="Hello,World!";
return _com_util::ConvertStringToBSTR(cstr);
}Linking...
Creating library Debug/dll.lib and object Debug/dll.exp
dll.obj : error LNK2001: unresolved external symbol "unsigned short * __stdcall _com_util::ConvertStringToBSTR(char const *)" (?ConvertStringToBSTR@_com_util@@YGPAGPBD@Z)
dll.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z)
Debug/dll.dll : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.dll.dll - 3 error(s), 0 warning(s)这些是什么错误?
USES_CONVERSION;extern "C" BSTR _stdcall MyFun(BSTR str)
{
USES_CONVERSION;
LPTSTR x = OLE2T(str);
}
TYPE_declspec(dllexport) MyFun(BSTR str)
{
...
...
}
其中,大写的TYPE表示是函数的类型,可以是各种类型的,如:void,int 等!
{
_bstr_t bstrTemp(str, true);
bstrTemp += "hello, world";
return SysAllocString(bstrTemp);
}