问题描述
运行应用程序后,我在Visual Studio 2005中获得第一次机会异常错误......任何人都帮我修复此问题....谢谢
[来自以下评论的复制代码]
I am Getting First-chance exception error in Visual Studio 2005, after running the application... Anyone help me to fix this ....Thanks
[Copied code from below comment]
void CEditBox_1Dlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
CString csSamplFreq;
char carrSamplFreq[50],csTemp[50];
char *pcSamplFreq = NULL;
pcSamplFreq =(char*)carrSamplFreq;
m_CntrlDisplay.SetFocus();
m_CntrlDisplay.GetWindowText(csSamplFreq);
strcpy(carrSamplFreq,(LPCSTR) (CStringA)csSamplFreq);
pcSamplFreq += usCurPos;
sprintf(csTemp,"%s",pcSamplFreq);
for(short sLoop = 0;sLoop<strlen((char*)csTemp);sLoop++)
{
*pcSamplFreq =csTemp[sLoop]; pcSamplFreq++;
}
*pcSamplFreq = '\0';
csSamplFreq.Format(L"%s",carrSamplFreq);
m_CntrlDisplay.SetWindowText(csSamplFreq);
usCurPos++;
m_CntrlDisplay.SetSel(usCurPos,usCurPos);
//m_CntrlDisplay=atoi(carrSamplFreq);
m_TxtSamplingFrequency = carrSamplFreq;
UpdateData(false);
}
推荐答案
strcpy(carrSamplFreq,(LPCSTR)(CStringA)csSamplFreq);
strcpy(carrSamplFreq,(LPCSTR) (CStringA)csSamplFreq);
这不是分配(宽) CString $ c $的正确方法c>内容到字符数组。
This is not the correct way for assigning a (wide) CString
content to character array.
pcSamplFreq + = usCurPos;
sprintf(csTemp,%s,pcSamplFreq);
pcSamplFreq += usCurPos;
sprintf(csTemp,"%s",pcSamplFreq);
我想 usCurPos
在那里失控。
我认为在你的情况下,如果你告诉我们想要实现什么而不是坚持修复丑陋的 CString-character数组
混合物,那可能会更好。
I suppose usCurPos
is out-of-control there.
I think in your case it would probably better if you tell us what are trying to achieve instead of insist on fixing the ugly CString-character array
mixture.
这篇关于如何修复.... 0xC0000005:访问冲突读取位置0xccdfc15c。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!