我是C++的新手,所以这可能是一个令人生厌的问题;我有以下功能:
#define SAFECOPYLEN(dest, src, maxlen) \
{ \
strncpy_s(dest, maxlen, src, _TRUNCATE); \
dest[maxlen-1] = '\0'; \
}
short _stdcall CreateCustomer(char* AccountNo)
{
char tmpAccountNumber[9];
SAFECOPYLEN(tmpAccountNumber, AccountNo, 9);
BSTR strAccountNumber = SysAllocStringByteLen(tmpAccountNUmber, 9);
//Continue with other stuff here.
}当我调试这段代码时,我传入了帐号"A101683“。当它执行SysAllocStringByteLen()部分时,帐号就变成了中文符号的组合……
有谁能对此有所了解吗?
发布于 2009-09-16 08:10:38
首先,包含SAFECOPYLEN的行有问题。它缺少')‘,并且不清楚它应该做什么。
第二个问题是在这段代码中没有使用AccountNo。tmpAccountNumber在堆栈上,可以包含任何内容。
发布于 2009-09-16 08:20:01
BSTR是双字节字符数组,所以您不能简单地将char*数组复制到其中。尝试使用L"A12323",而不是传递"A12123"。
short _stdcall CreateCustomer(wchar_t* AccountNo)
{
wchar_t tmpAccountNumber[9];
wcscpy(tmpAccountNumber[9], AccountNo);
BSTR strAccountNumber = SysAllocStringByteLen(tmpAccountNUmber, 9);
//Continue with other stuff here.
}https://stackoverflow.com/questions/1431598
复制相似问题