读书人

pb调用vc dll 字符串char *参数的有关

发布时间: 2013-03-16 11:51:46 作者: rapoo

pb调用vc dll 字符串char *参数的问题
*.h文件

#ifdef SZ_EXPORTS
#define SZ __declspec(dllexport)
#else
#define SZ __declspec(dllimport)
#endif
extern "C"
{

//开启设备
SZ int __stdcall OpenDevice(char* pstrCom, int* nHandle, int nFage = 0);
。。。。

*.cpp文件
//开启设备
SZ int __stdcall OpenDevice(char* pstrCom, int* nHandle, int nFage)
{


if(ERR_NO_ERROR != nRet)
{
Writelog("!!! <--OpenDevice(%s) 失败 返回值 = %d",pstrCom,nRet);
} else {
Writelog("<--OpenDevice(%s) 成功 返回值 = %d",pstrCom,nRet);
}
return nRet;
}

*.def文件
LIBRARY"Bbb.dll"

EXPORTS

OpenDevice@1
CloseDevice@2

pb调用代码

Function int OpenDevice(ref string AA , Ref int BB, int CC) Library "Bbb.dll"

String ls_port
ls_port = space(128)
ls_port ='COM3:9600:E:8:1'
ll_c =OpenDevice(ref ls_port, ll_b, 0)

根据日志,ls_port 数据应该为:COM3:9600:E:8:1,但是只识别为C所以程序执行出错
dll
[解决办法]
改为这个试试

Function int OpenDevice(ref string AA , Ref int BB, int CC) Library "Bbb.dll;Ansi"
[解决办法]
我做了一个小测试:
C++:
*.cpp


unsigned long __stdcall GetText( char * as_value)
{
int li_len=lstrlenA(as_value);

MessageBox(NULL,ToWChar(as_value), L"A",MB_OK);
return 1;
}


PB调用:

函数声明:
function long GetText(ref string as_value) library "myCAPI-1.dll"
调用:
String ls_port
long ll_rtn
ls_port = space(128) //这句实际没有任何作用,可以去掉
ls_port ='COM3:9600:E:8:1'
ll_rtn=gettext(ref ls_port)


结果正常,建议你也给客户类似的测试,写一个messagebox直接返回参数

读书人网 >PB

热点推荐