CString url=_T("httt;//wwwwwwww.com");
int a=0;
USES_CONVERSION;
while (true)
{
string str=T2A(url.LockBuffer());
url.UnlockBuffer();
TRACE(_T("%d\n"),a);
a++;
Sleep(1);
}
CString url=_T("httt;//wwwwwwww.com"); int a=0;
USES_CONVERSION;
while (true)
{
string str=T2A(url.GetBuffer(0));
url.ReleaseBuffer();
TRACE(_T("%d\n"),a);
a++;
Sleep(1);
}出来两个错误提示0x7c92e5aa 处最可能的异常: 0xC0000005: 写入位置 0x00030ffc 时发生访问冲突
0x7c92e5aa 处未处理的异常: 0xC0000005: 写入位置 0x00030ffc 时发生访问冲突有谁知道这个是怎么回事么?
谢谢了!
正确的代码该如何写呢?
果然微软的mvp不一样Q: How do we overcome this Stack Overflow problem?A: By not using the macros.
他建议不要使用 如果我就单独一个函数出来
如string getstr(CString csstr)
马上返回string可以么?
可以,但不能作为内联函数,
_alloca在所在函数结束后才修复平衡栈string getstr(CString csstr)
{
string str;
USES_CONVERSION;
string str=T2A(url);
return str;
}或者自行使用WideCharToMultiByte转换
#if def _UNICODE || defined UNICODE
str.reserve(url.GetLength());
WideCharToMultiByte(CP_ACP,0,url,-1,str.data(),url.GetLength(),NULL,NULL);
#elseif
str=url;
#endif
{
string str;
USES_CONVERSION;
string str=T2A(csstr);
return str;
} 或者自行使用WideCharToMultiByte转换
#if defined _UNICODE || defined UNICODE
str.reserve(url.GetLength());
WideCharToMultiByte(CP_ACP,0,url,-1,str.data(),url.GetLength(),NULL,NULL);
#elseif
str=url;
#endif
一直不会用!