佚名通过本文主要向大家介绍了cstring转char,cstring char,cstring转char数组,cstring转const char,mfc cstring转char等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: OCX中char转CString报Unhandle exception in exeMFC42Ddll:0xc0000005
描述:
解决方案1:
描述:
OCX中,我想把char*转CString
报Unhandle exception in **.exe(MFC42D.dll):0xc0000005 Access Violation
代码如下:
byte OutData[256];
memset(OutData,0,sizeof(OutData));
memcpy(OutData,bTmpOutInfo,256); //bTmpOutInfo为前面生成的数据,我把他拷贝到OutData
m_transOutData.Format("%s",OutData); //这就报错了?
网上查了下,好像是堆栈或者内存溢出,但不知道怎么改,有高手知道么?
解决方案1:
肯定是你buffer overrun了吧,你把byte数组,转换成LPTCSTR给format
你打开memory看看有没有越界呀,
不行发给我看看
gw_net@163.com
你还可以启动RTC,
Sorry
BYTE OutData[256] = {'A', 'B', 'C', 'D', 'E', 'F', '\0'};
char buf[256+1] = {0};
memcpy(buf, OutData, 256);
CString str(buf);
AfxMessageBox(str);

