返回信息流我要从一个DLL文件中调用一个函数,这个函数的功能是向一个设备发送命令,然后设备收到命令后再给出回应,函数的原型是int SendCommand(string command)。这个DLL文件可能是用VB编写的,DLL文件时卖设备的公司提供的。
调用这个函数的时候,如果用VB来编写,int iReturn = SendCommand("#IDN?" & " " & vbLf),命令要求以#开始,然后设备根据换行符vbLf来判断命令是否结束,这样发过去后设备能够给出正确的响应。
但我们要求是用VC来编写,我最开始是这样写的,
string str("#IDN? \n");int iReturn = SendCommand(str);
发过去后,设备不能给出正确的响应,后来发现可能是因为VB中的string是unicode的,而VC的默认是MBCS的,然后就采用wstring又试了一次,结果还是不对
wstring str(L"#IDN? \n");int iReturn = SendCommand(str);
然后也试了用CString字符串来发送命令,还是不行,我把我力所能及的办法都试了一遍还是不行。。这几天因为这个都要崩溃了,恳请各位大牛帮忙看看到底是哪儿出了问题!真的谢谢了!
这是一条镜像帖。来源:北邮人论坛 / cpp / #38239同步于 2010/4/19
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
求助:VC使用DLL中的函数遇到问题!!!
cyysd
2010/4/19镜像同步4 回复
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
设备的手册上有这么一段话:
Commands and queries to the sm125 are in the form of ASCII strings that begin with a #character and end with a linefeed (ASCII char 10 [0x0a in hex, ‘\n’ in C, vbLf in VisualBasic]). All characters sent to the sm125 are internally buffered until a linefeed character is detected.
大概意思就是说命令是以#号开始,换行符结束的,然后命令要是ASCII strings形式的,不知道从这里能不能看出我程序的问题来
编译过不了,说
error C2065: 'wchar' : undeclared identifier
error C2677: binary '*' : no global operator defined which takes type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)
是不是要加什么头文件?我对wchar这种类型不太了解。。
【 在 jmpesp 的大作中提到: 】
: wchar* str = L"#IDN? \n";
: int iReturn = SendCommand(str);
: --
: ...................
试试:
string str("#IDN?\n");
int iReturn = SendCommand(str.c_str());
【 在 cyysd 的大作中提到: 】
: 编译过不了,说
: error C2065: 'wchar' : undeclared identifier
: error C2677: binary '*' : no global operator defined which takes type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)
: ...................