程序运行结束后总是显示:Run-Time Check Failure #2

程序运行结束后总是显示:Run-Time Check Failure #2 - Stack around the variable 'cmd_value' was corrupted.

程序过程运行正确,调试发现程序运行结束之后就会报告这个错误。
而且**只有d的数值在0到1(不包括1)**才会发生这样的错误。
我的编程环境是vs2010.

double d=0;
BYTE cmd_star[]="$";
BYTE cmd_cmd[]="001";
BYTE cmd_mid[]=",";
char cmd_value[7];
_gcvt_s(cmd_value,sizeof(cmd_value),d,5);
BYTE cmd_end[]="#";
BYTE cmd2[13];

memcpy(cmd2,cmd_star,sizeof(char));
memcpy(cmd2+1,cmd_cmd,3*sizeof(char));
memcpy(cmd2+4,cmd_mid,sizeof(char));
memcpy(cmd2+5,cmd_value,6*sizeof(char));
memcpy(cmd2+11,cmd_end,sizeof(char));

CWnd * pMain=(CWnd*)AfxGetMainWnd();

Eol.hEvent=CreateEvent(NULL,        
    TRUE,           // manual-reset event 
    FALSE,          // not signaled
    NULL);

if(!::SetCommState(hComFile,&m_BCD))
{
    //AfxMessageBox("SetCommState() error!");
    errmsg = "串口设置失败!";
    p = (LPSTR)(LPCTSTR)errmsg;
    ::SendMessage(pMain->m_hWnd,UM_ERRORMSG,0,(LPARAM)p);
    return ;
}

::EscapeCommFunction(hComFile,SETDTR);

if(WriteData(cmd2,13)!=13)
{
    //AfxMessageBox("Write com error!");
    errmsg = "串口写入失败!";
    p = (LPSTR)(LPCTSTR)errmsg;
    ::SendMessage(pMain->m_hWnd,UM_ERRORMSG,0,(LPARAM)p);
    return;
}
if (Eol.hEvent!=NULL)
{
    ResetEvent(Eol.hEvent);
}

CloseHandle(Eol.hEvent);

4个回答

BYTE cmd_star[]="$";
BYTE cmd_cmd[]="001";
BYTE cmd_mid[]=",";
这些都是常量,而且大小都很小。你把这些都定义的大一些不可以么

willzoe
willzoe 执行这些语句的时候都是正常的,只是这段代码执行完毕之后就会弹出对话框提示这个错误。
接近 4 年之前 回复

一般是内存操作失败造成的。有可能是你的字符数组拷贝出错了。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Run-Time Check Failure #2
const int MLEN = 1024 * 350;rn char recvBuf[MLEN],headBuff[800];rn char *tempBuff;rn。。。。。。。。。。。。。。。。。。。。。。。。。。。rn tempBuff = strstr(recvBuf,"\r\n\r\n");rn strcpy_s(pContent,strlen(pContent),tempBuff+4);rn strncpy_s(headBuff,strlen(headBuff),recvBuf,strlen(recvBuf)-strlen(tempBuff));rnrnRun-Time Check Failure #2 - Stack around the variable 'headBuff' was corrupted.rnrn我调试看到recvBuf和headBuff的值都是对的。但这个函数调用完就报上面那个错误。
CButtonST; Run-Time Check Failure #2
调用一个对话框rnCTestDlg qsdlg;rnqsdlg.DoModal();rnrnqsdlg.h里加了这么一句话, rnCButtonST m[2];rnrn然后就出现Run-Time Check Failure #2 - Stack around the variable 'qsdlg' was corruptedrn////////////rn要是rnCButtonST m;rn就不会出错。。。rn对CButtonST 不太熟。。大家帮帮忙啊
求教Run-Time Check Failure #2
为什么在对话框中使用一个rnCArray m_tree;rn就没事,使用两个就rnCArray m_tree;rnCArray m_classroom;rn就Run-Time Check Failure #2?rn我已经注释掉了所有操作代码,只是申明而已。rn就Run-Time Check Failure #2是退出模态对话框DOModal()函数返回时出错的。rnrn下面是sch_cla_clr的代码:rnclass sch_cla_clrrnrnpublic:rn sch_cla_clr(void);rn ~sch_cla_clr(void);rnpublic:rn double item_id;rn double cla_id;//那个班rn double sub_id;//什么科目rn int t_hour;//什么时候上rn int lessonType;//全学期还是单双周rn int cla_number;//班里有多少人rn double th_id;//什么老师上rn double clr_id;//那个教室上rn int d_time;//什么时间段上rn;rnrnsch_cla_clr(void);rn~sch_cla_clr(void);rnrn
关于“Run-Time Check Failure #2”
getbits(value ,s1,s2)功能:rn保留value从第s1位到第n2位,其它余位为0.rnrn上码:rnrn#includernvoid main()rnrn unsigned short int getbits(unsigned short int value,int s1,int s2);rn unsigned short int n;rn int n1,n2;rn scanf("%o",&n);rn scanf("%d,%d",&n1,&n2);rn printf("%o",getbits(n,n1-1,n2));rnrnunsigned short int getbits(unsigned short value,int s1,int s2)rnrn unsigned short int z;rn z=~0;rn z=(z>>s1)&(z<<(16-s2));rn z=value&z;rn z=z>>(16-s2);rn return z;rnrnrn编译无错,运行结果正确,但出现出“Run-Time Check Failure #2 - Stack around the variable 'n' was corrupted”。rnrn求解。
Run-Time Check Failure #3
编译c++程序时总是出现对话框显示Run-Time Check Failure #3 - The variable 'comstat' is being used without being initialized.rn用6.0编译时没问题,但到了2008就出现以上问题!rn我是这样定义comstat的:COMSTAT comstat;rn我该怎样解决?谢谢
run-time check failure #3
pBmpBits = NULL;//在构造函数中rn///////rnif(hMemDC)rnrn pBmpBits = new UCHAR[bufsize];rnrnrn::GetDIBits(hdc, hbitmap, 0, bm.bmHeight, [color=#FF0000]pBmpBits[/color], binf,DIB_PAL_COLORS);rndelete pBmpBits;rnpBmpBits = NULL;rnrn出错rnrun-time check failure #3 The variable ‘pBmpBits’ is being used without being defined.rnrn奇怪的是运行一段时间后才出现错误,这是为什么啊,谢谢rnrnrn
Run-Time Check Failure #2这个是什么错误?
我的程序在执行中,函数返回调用的时候报错:rnRun-Time Check Failure #2 - Stack around the variable 'IDAndT' was corrupted.rn其中'IDAndT' 是我定义的一个结构:rnstruct SMIDAndTrnrn int ID;rn CTime MT;rn;rn函数中的定义是这样的:SMIDAndT IDAndT[4];rn我完全不明白这个提示的含义,MSDN里面也没有能够找到. :(rn请问各位大侠,这个提示是什么意思?如何解决?
run-time check failure #2 stack around variable
能输出正确结果可是弹出这个错误窗口是怎么回事?nnn```n#includen#includennint main()n int a[3];nn for (a[0] = 1; a[0] < 21; a[0]++)n for (a[1] = 1; a[1] < a[0]; a[1]++)n for (a[2] = 1; a[2] < a[1]; a[2]++)n for (a[3] = 1; a[3] < a[2]; a[3]++)n n if (abs(1.0 / a[0] + 1.0 / a[1] + 1.0 / a[2] + 1.0 / a[3] - 1) < 0.0001)n printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]);n nn return 0;nn n```nn
为什么报Run-Time Check Failure #2的错误?
char m_Scan_Char[] = "0";rnprintf("Scan:"); rnscanf("%s",m_Scan_Char);rnrnint m_Comp = strcmp(m_Scan_Char,m_SN);rnif (m_Comp == 0)rn rn printf("Pass....\n"); rnrnelsernrn printf("Fail....\n");rn return false;rnrnrnreturn true;rnrn运行完后,弹出对话框,报的错误是:rnRun-Time Check Failure #2 - Stack around the variable 'm_Scan_Char' was corrupted.rnrn
简单程度导致 Run-Time Check Failure #2 -
// Test.cpp : Defines the entry point for the console application.rn//rnrn#include "stdafx.h"rn#include rn#include rnrntypedef struct ip_addressrnrn u_char byte1;rn u_char byte2;rn u_char byte3;rn u_char byte4;rnip_address;rnrntypedef structrnrn ip_address src_addr;rn unsigned short src_port;rn ip_address dest_addr;rn unsigned short dest_port;rnsocket_pair;rnrnrnrnint _tmain(int argc, _TCHAR* argv[])rnrn socket_pair cp;rn std::string a("192.168.0.1:80-10.0.11.21:5689");rn sscanf(a.c_str(), "%d.%d.%d.%d:%d-%d.%d.%d.%d:%d", rn &cp.src_addr.byte1, rn &cp.src_addr.byte2,rn &cp.src_addr.byte3,rn &cp.src_addr.byte4,rn &cp.src_port, rn &cp.dest_addr.byte1, rn &cp.dest_addr.byte2, rn &cp.dest_addr.byte3, rn &cp.dest_addr.byte4, rn &cp.dest_port);rn printf("hele");rn return 0;rnrnrn
Run-Time Check Failure #0 问题
第三方提供的接口如下:rn virtual HRESULT __stdcall AddReceiver (rn /*[in]*/ BSTR bszReceiver,rn /*[in]*/ BSTR bszReceiverName ) = 0;rnrnIAMMessagePtr IMessagePtr;rnCString strReceiver= m_strReceiver;rnCString strReceiverName= _T("");rnIMessagePtr->AddReceiver((_bstr_t)strReceiver, (_bstr_t)strReceiverName);rn调试至上一语句出现以下错误。rnRun-Time Check Failure #0 - The value of ESP was not properly saved across a function call.rn高手解决下.谢谢。
Run-Time check Failure #0异常
先谢谢大家了,rn[img=http://img.my.csdn.net/uploads/201303/26/1364307386_8766.jpg][/img]rn异常:Run -Time Check Failure #0- the value of esp was not properly saved across a function call, this is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention rnrn指向如下位置:rn[code=c]#include "stdafx.h"rn#include "occimpl.h"rn#define new DEBUG_NEWrnrn/////////////////////////////////////////////////////////////////////////////rn// AfxDlgProc - does nothing since all messages are handled via AfxWndProcrnrnINT_PTR CALLBACK AfxDlgProc(HWND hWnd, UINT message, WPARAM, LPARAM)rnrn if (message == WM_INITDIALOG)rn rn // special case for WM_INITDIALOGrn CDialog* pDlg = DYNAMIC_DOWNCAST(CDialog, CWnd::FromHandlePermanent(hWnd));rn if (pDlg != NULL)rn return pDlg->OnInitDialog(); // 指向此处,rn elsern return 1;rn rn return 0;rn[/code]rnrn我想问一下,为什么图片上老是出现这种异常,我查过相关资料都是说栈溢出,栈中内存越界,最有可能出现在一些指针和数组等情况,本人调试能力不是强,最后希望各位大神能指点一下,希望给出点调试方面的经验和资料,小弟不甚感激
哎~~~ run-time check failure #0
我对这个东西彻底无解了。。于是只好到论坛上求助各位。rnrn是我在试图改hge代码时出现的问题。rnrn我之前在函数里头修修补补,删删改改,都没有问题的。rnrn而当我想要添加一个函数时。出现这个问题,完整提示如下:rnRun-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.rnrn添加的代码如下:(有注上注释的是添加的,没有的是原来的)rnrnhge.h中rn[code=C/C++]rn #define CALL __stdcallrn virtual bool CALL System_Start() = 0;rn virtual void CALL System_Active() = 0;//新添函数rn virtual char* CALL System_GetErrorMessage() = 0;rn[/code]rnrnhge_impl中rn[code=C/C++]rn virtual bool CALL System_Start(); rn virtual void CALL System_Active();//新添函数rn virtual void CALL System_SetStateBool (hgeBoolState state, bool value);rn[/code]rnrn实现在system.cpp中rnrn[code=C/C++]void CALL HGE_Impl::System_Active()//新添函数rnrn this->bActive = true;rnrn[/code]rnrn没有添加之前, 可以运行, 而添加之后则会在System_SetState函数里出问题, System_SetState是hge.h中的内联函数rn定义如下:rn[code=C/C++] inline void System_SetState(hgeStringState state, const char *value) System_SetStateString(state, value); rn[/code]rnrnSystem_SetStateString的声明如下:rnrn[code=C/C++]rn virtual void CALL System_SetStateString(hgeStringState state, const char *value) = 0;[/code]rnrn这个函数进入不了, 跳出前述的错误,奇怪的是错误出现的位置并不是调用我写的函数的位置,而是之前。rnrn我有在网上查来查去,说调用约定不对,或者栈溢出什么的,可是我这里都用了__stdcall,而且即使函数没有内容,也报错。。rnrn不知道我提供的信息够不够rn有没有遇到过类似问题的高手..给本人指点迷津下,不胜感激!
Run-Time Error Check Failure #0
MSXML2::IXMLDOMElementPtr pe;rn MSXML2::IXMLDOMAttributePtr pa;rn pe = _XMLDoc->selectSingleNode("//Project");rn MessageBox(pe->xml);rn if ( pe != NULL )rn pa = _XMLDoc->createAttribute(_bstr_t("ProgramName"));rn if ( pa != NULL )rn pa->value = _TextProgramName.ToString().GetBuffer(0);rn pe->setAttributeNode(pa);rn pa.Release();rn rnrn执行到pe->setAttributeNode(pa);的时候报出异常rnrnRun-Time Error Check Failure #0—The value of ESP was not properly savedrnacross a function call. This is usually a result of calling a functionrndeclared with one calling convention with a function pointer declaredrnwith a different calling convention.rnrn不知道这是个什么异常!rn程序编译没问题,pe得到了指针,并且打印出xml数据一点错误也没有。rn到了添加属性的时候出现异常。而且我头一次见到这个!rn谁知道怎么解决!
myGSL :Run-Time Check Failure #0 ,求解决
源代码:rnextern "C"rnrn#include "my++/myhead.h"rn;rnint main()rn rn Complex x=newComplex();rn return 0;rn rnError:Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.rnrn好像调用其他复数函数也是这种错误,如getComplexVector,已经试过__stdcallrnrnmyGSL 4.0;VS2010;win7;
VC++错误:Run-Time Check Failure #0
VC++错误:rn运行时错误。是调用一个已编译成功的DLL,编译程序时工程没有错误。运行时出现下列错误提示。rnRun-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
几个 Run-Time Check Failure #N 的问题
环境:Visual Studio.Net 2003rn类型:Debugrn以下代码作了简化,有谁有Run-Time Check Failure 资料请赐教rnrn代码1rn#include "stdafx.h"rnvoid malice()rnrn printf("Hey,you're been attacked.\n");rnrnrnvoid foo()rnrn int *ret;rn ret=(int*)&ret+2;rn (*ret)=(int)malice;rnrnrnint _tmain(int argc, _TCHAR* argv[])rnrn foo();rn return 0;rn rn运行后出现:rnRun-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.rn rnrn代码2rn#include "stdafx.h"rnvoid foo()rnrn int var[2];rn var[2] = 0;rnrnrnint _tmain(int argc, _TCHAR* argv[])rnrn foo();rn return 0;rnrn运行后出现:rnRun-Time Check Failure #2 - Stack around the variable 'var' was corrupted. rnrn#include "stdafx.h"rn#include rnusing namespace std;rnrnint a,b;rnint _tmain(int argc, _TCHAR* argv[])rnrn int c;rn cout<
Run-Time Check Failure #3是什么错误?
Run-Time Check Failure #3 - The variable "ptr" is being used without being definedrn是为什么?(我定义了ptr啊)
Run-Time Check Failure #0的问题,求救
是这样的,我用的是virtools的SDK(不知道是什么不要紧,就是个做3D的平台),调用他SDK中的函数然后用VC自己编了个DLL,但是用的时候就报错了,然后不正常退出rnrn调试时出现下面错误提示:rnrnRun-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.rnrn到底怎么回事?我说这么多大家能明白吗
在vc.net2003下调试出现Run-Time Check Failure #3
我要画一个圆弧,编译都通过了,可是就是画的时候要出现Run-Time Check Failure #3 - The variable 'm_Fill' is being used without being defined.rn可是这个m_Fill我明明定义了啊?这是怎么回事啊?rn下面是我的代码rnBOOL CDrawView::jsarc(CPoint p1,CPoint p2,CPoint p3,float *CircleX,float *CircleY,float *CircleR,float *Angle1,float *Angle2)rnrnfloat k1,k2,an1,an2,an3;rnfloat x1,y1,x2,y2,x3,y3,xx1,xx2,yy1,yy2,xx,yy,rr;rn//将三个点的坐标赋给浮点变量rnx1=(float)p1.x;y1=(float)p1.y;rnx2=(float)p2.x;y2=(float)p2.y;rnx3=(float)p3.x;y3=(float)p3.y;rnif (x1==x2&&y1==y2||x1==x3&&y1==y3||x2==x3&&y2==y3) //如果有两个点的坐标相同rn return false; //操作不成功,返回FALSErn//得到顺三点方向的两条直线段中点的坐标rnxx1=(x1+x2)/2;yy1=(y1+y2)/2;rnxx2=(x3+x2)/2;yy2=(y3+y2)/2;rnif (fabs(y2-y1)>0.5) //如果第一条直线段的垂线不是竖直线rn k1=-(x2-x1)/(y2-y1); //得到第一条直线段垂线的斜率rnif (fabs(y3-y2)>0.5) //如果第二条直线段的垂线不是竖直线rn k2=-(x3-x2)/(y3-y2); //得到第二条直线段垂线的斜率rnif (k1==k2&&k1==0.0)rn return 0;rnif (fabs(y2-y1)<0.5) //如果第一条直线段是水平线(即第一条直线段的垂线是竖直线rnrn xx=xx1;rn if (fabs(y3-y2)<0.5) //如果第二条直线段也是水平线rn rn yy=y2+10000; //给定圆弧的半径为10000rn rr=10000;rn rn else //如果第二条直线段不是平行线(即第二条直线段的垂线不是竖直线)rn rn yy=yy2+k2*(xx2-xx); //求得圆心的纵坐标rn rr=yy-yy2;rn if(rr<0)rn rr=-rr; //得到圆的半径rn rnrnelse if (fabs(y2-y3)<0.5) //如果第二条直线是水平线,而第一条直线不是水平线rnrn yy=yy1+k1*(xx1-xx); //解得圆心得y坐标rn rr=yy-y2;rn if (rr<0)rn rr=-rr; //得到圆得半径rnrnelse //如果两条直线段都不是水平线(即两条直线段得垂线都不是竖直线)rnrn if(k1==k2) //如果两条直线段平行(即三个点在一条直线上rn rn //以下假定这个圆弧半径为10000,求得圆心坐标rn xx=x2+(float)(10000/sqrt(1+k1*k1)); //圆心横坐标rn yy=y2+(float)(10000/sqrt((1+k1*k1)/(k1*k1))); //圆心纵坐标rn rr=10000; //圆的半径rn rn else //如果两条直线段不平行rn rn //解得两条直线段的垂线的交点,即圆心的坐标rn xx=(yy2-yy1+k1*xx1-k2*xx2)/(k1-k2); //圆心横坐标rn yy=yy1+k1*(xx-xx1); //圆心纵坐标rn rr=(float)sqrt((xx-x1)*(xx-x1)+(yy-y1)*(yy-y1)); //圆的半径rn rn rnrn//将圆心和半径都转成实际坐标rn*CircleX=m_xStart+blc*xx;rn*CircleY=m_yStart+blc*(m_hScreen-yy)*blc;rn*CircleR=blc*rr;rnan1=(float)acos((x1-xx)/rr); //得到第一个点相对于圆心的弧度rnif(y1-yy>0)rn an1=(float)(pi*2-an1);rn an2=(float)acos((x2-xx)/rr); //得到第二个点相对于圆心的弧度rnif(y2-yy>0)rn an2=(float)(pi*2-an2);rn an3=(float)acos((x3-xx)/rr); //得到第三个点相对于圆心的弧度rnif(y3-yy>0)rn an3=(float)acos(pi*2-an3);rnif(an2>an1&&an2GetGraphID(4); //得到要增加圆弧的唯一识别号rnpDoc->AddArc(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,m_CircleX,rn m_CircleY,m_CircleR,m_Fill,m_Angle1,m_Angle2)->Draw(&ht,0,0,m_bColor); PushNumb=0; //按下鼠标左键次数为0,重新进行圆弧的绘制rnReleaseCapture(); rnrnvoid OnMouseMove(nFlags, point)rnrnif (PushNumb==2&&mPointOld!=point) //如果按下两个点且当前鼠标移动点与上个移动点不同rnrnif(DrawArcYes>0) //如果已经在视图中绘制了m_Arc1对象存储的圆弧rnm_Arc1.Draw(&ddd,1,0,m_bColor); //重画以擦除圆弧rnpb=jsarc(mPointOrign1,mPointOrign,point,&m_CircleX,&m_CircleY,&m_CircleR,rn &m_Angle1,&m_Angle2); //计算经过当前鼠标移动点的圆弧的几何要素rnif(pb) //如果能计算得到圆弧的几何要素,初始化m_Arc1对象并绘制这个圆弧rnrnm_Arc1.Initrn(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,0,m_CircleX,m_CircleY,m_CircleR,0,m_Angle1,m_Angle2);rnm_Arc1.Draw(&ddd,1,0,m_bColor);rnrnDrawArcYes=pb; //判断这次是否绘制了m_Arc1对象rnmPointOld=point;rnrnrnvoid OnRButtonDown(UINT nFlags, CPoint point)rnrnif(PushNumb==2) //已经按下两个点,正在拖动圆弧rnm_Arc1.Draw(&ddd,1,0,m_bColor); //擦掉拖动的圆弧rnPushNumb=0;rnReleaseCapture(); //释放捕捉的鼠标rnrn rn
紧急求助:Run-Time Check Failure #3
小弟在VS2005平台下学习陆老大的 directshow开发指南, rn用FilterMpeg2VD例子生成了HD MPEG2-Decoder Filter, rn然后用DirectX sdk 提供的GraphEdit设计了一个filter播放链 rn用来播放一个.vob格式的视频文件, rn可是运行的时候却graphedit.exe现程序异常(换成其他的filter时其工作完全正常), rndebug时在CMpegController::DecodeOnePicture()出现断点, rncontinue后出现Run-Time Check Failure #3 - The variable 'motion_type' is being used without being definedrnrn可"motion_type"在之前已经被定义为 int了,为什么编译器还说没有定义呢? rnaddwatch时候显示如下:motion_type -858993460 int rn难道是这个数值太打了超出范围? rn望高手指教!! rnrn
请问这是什么: Run-Time Check Failure #0
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.rnrn上面这段是我在调用函数时出来的提示信息.rn结果就是程序OVER了.rnrn还请指教是什么原因造成的.rn谢谢
directshow测试程序Run-Time Check Failure #0错误
从书上抄了个dshow的小程序,想播放f盘下的12.rmvb文件,在运行到hr=pGraph->RenderFile(L"F:\\12.rmvb",NULL);时出现了如下错误rnRun-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.rn(12.rmvb可以通过graphedit正常播放)rn从网上搜了下,说是函数调用方式的问题,不太懂,求高手帮忙!!rnrn// aviplayer.cpp : 定义控制台应用程序的入口点。rn//rnrn#include "stdafx.h"rn#includern#pragma comment(lib,"strmiids.lib")rnrnint _tmain(int argc, _TCHAR* argv[])rnrn IGraphBuilder *pGraph=NULL;rn IMediaControl *pControl=NULL;rn IMediaEvent *pEvent=NULL;rnrn HRESULT hr=CoInitialize(NULL);rn if(FAILED(hr))rn rn printf("ERROR- Could not initalize Com library\n");rn return -1;rn rnrn hr=CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,IID_IGraphBuilder,(void**)&pGraph);rn if(FAILED(hr))rn rn printf("ERROR- Could not craete the Filter Graph Manager.\n");rn return -1;rn rnrn hr=pGraph->QueryInterface(IID_IMediaControl,(void**)&pControl);rn hr=pGraph->QueryInterface(IID_IMediaEvent,(void**)&pGraph);rnrn hr=pGraph->RenderFile(L"F:\\12.rmvb",NULL);rn if(SUCCEEDED(hr))rn rn hr=pControl->Run();rn if(SUCCEEDED(hr))rn rn long evCode;rn pEvent->WaitForCompletion(INFINITE,&evCode);rn rn rnrn pControl->Release();rn pEvent->Release();rn pGraph->Release();rn CoUninitialize();rn printf("test success!");rn return 0;rn
向一个类中添加变量,报错run-time check failure #2
有一个基于对话框的类CQueryDlg,基类是CDialogrn在下面函数中定义了这个类的局部变量来显示一个模态对话框,代码如下:rnvoid CMainFrame::OnTest()rnrn CQueryDlg QueryDlg;rn QueryDlg.DoModal();rnrn运行正常,但是只要我往CQueryDlg类中添加成员变量,运行的时候就在“”位置报错run-time check failure #2—Stack around the variable 'QueryDlg' was corrupted.rnrn为什么?rnrn我查了一些资料,都是说数组的,这种情况有人遇到过吗?rn
请教一个关于Run-Time Check Failure #2的错误
各位帮忙看看下面一段代码:rn#include rnusing namespace std;rnrnvoid main()rnrn char CPL[] = "01fd6ce36da24be5b3c7422260c2169b";rn char CPLID[17];rn memset(CPLID, 0, 17);rnrn for (int i = 0; i < 16; i++)rn rn sscanf(CPL + 2 * i, "%02x", CPLID + i);rn rnrn编译可以通过,执行时提示:rnRun-Time Check Failure #2-Stack around the variable 'CPLID'was corrupted.rn可是我实在找不出CPLID那个地方用错了。谢谢!!!rn另外上述代码在vs.net2003上会出现如上问题,可是在vc6.0下就不会出现上述问题,请各位帮忙!!!谢谢
帮忙 “Run-Time Check Failure #2 - Stack around the variable 'bmpinfo' was corrupted.”
程序运行时出现这样的错误rn“Run-Time Check Failure #2 - Stack around the variable 'bmpinfo' was corrupted.”rn在网上查找了相关信息,大概是说stack溢出或什么对齐之类的rnrn也有的说是把“c/c++代码生成这项”的"两者(/RTC1,等同于 /RTCsu)"改为默认值,这样改了,错误是消失了,但程序运行就得不到我想要的结果rn[code=C/C++]rnBOOL CLSDC::RemoteDisplay(HBITMAP hbitmap, RECT size)rn rn BITMAP bmp;rn GetObject(hbitmap, sizeof(BITMAP), &bmp);rnrn const int dataSize = (bmp.bmWidthBytes * bmp.bmHeight );rnrn m_pMsgData = MapViewOfFile(m_hMsgFile, FILE_MAP_READ | FILE_MAP_WRITE,rn 0, 0, 0);rnrn if (m_pMsgData == NULL)rn return FALSE;rnrn HDC hdc = GetDC(NULL);rn HBITMAP bitmap = CreateCompatibleBitmap(hdc, bmp.bmWidth, bmp.bmHeight);rnrn BITMAPINFO bmpinfo;rn bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);rn bmpinfo.bmiHeader.biBitCount = 0;rnrn int res;rn res = ::GetDIBits(hdc, bitmap, 0, 1, NULL, &bmpinfo, DIB_RGB_COLORS);rn if(res == 0)rn return FALSE;rnrnrn SelectObject(hdc, hbitmap);rnrn GetDIBits(hdc, hbitmap, 0, bmp.bmHeight, m_pMsgData, &bmpinfo, DIB_RGB_COLORS);rnrn UnmapViewOfFile(m_pMsgData);rn rnrn return TRUE;rn rn[/code]
【求助】Run-Time Check Failure #2 - Stack around the variable 'app' was corrupted.
通过一句一句代码注释调试,好像知道问题出在哪儿。但因为不知道为什么出错,就找不到解决的方法。rn简化代码如下:rn[code=C/C++]rnint WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )rnrn BaseApplication app;rn tryrn rn app.go();rn rn catch(Ogre::Exception e)rn rn MessageBox(NULL, e.getFullDescription().c_str(),"Error",MB_OK);rn rn[/code]rncatch语句块不会执行,错误是执行到最后一个大括号抛出的。rnBaseApplication是一个类,问题就出来它的一个成员变量mpOgreHead上。mpOgreHead是一个指针,初始化为NULL。在建立场景之后,mpOgreHead就指向一个地址(假设为a)。在运行过程中的事件处理函数里面,首先delete掉地址a,mpOgreHead=NULL,然后再new一个地址b,让mpOgreHead指向b(因为用户选择的需要),过程就是这样的。rn但是运行到最后的最后时,就会“当”出错,提示如题。
Run-Time Check Failure #2 - Stack around the variable 'm_osWrite' was corrupted
以下是菜鸟的向串口写字符串的函数rn[code=c]rnvoid ProcessSndBuffer(BYTE *buffer, DWORD size, int comIndex)rnrn tryrn rn OVERLAPPED m_osWrite;rn memset(&m_osWrite, 0, sizeof(m_osWrite));rn m_osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);rn COMSTAT ComStat;rn DWORD dwErrorFlags, dwBytesWritten, dwRes;rn BOOL bWriteStat;rn ClearCommError(hComArray[comIndex], &dwErrorFlags, &ComStat);rn bWriteStat = WriteFile(hComArray[comIndex], buffer, size, &dwBytesWritten, &m_osWrite);rn if(!bWriteStat)rn rn DWORD dwLastError = GetLastError();rn if(GetLastError() == ERROR_IO_PENDING)rn rn dwRes = WaitForSingleObject(m_osWrite.hEvent, 1000);rn if (dwRes == WAIT_OBJECT_0)rn rn while(!GetOverlappedResult(hComArray[comIndex], &m_osWrite, &dwBytesWritten, TRUE))rn rn DWORD dwError = GetLastError();rn if (dwError == ERROR_IO_INCOMPLETE)rn continue;rn rn rn rn rn CloseHandle(m_osWrite.hEvent);rn rn catch (...)rn rn rn[/code]rnrn然后运行一会儿就报错退出:Run-Time Check Failure #2 - Stack around the variable 'm_osWrite' was corruptedrn好吧,引起这个错误的可能是别的地方内存操作越界引起的,但是为虾米每次俺运行都是这里错呢?rn另外俺把memset(&m_osWrite, 0, sizeof(m_osWrite));这句注释了它貌似就不报错了。。。只不过这样WriteFile会返回LastError参数错误。。。
Run-Time Check Failure #2 - Stack around the variable 'dy' was corrupted.
本人写了一个全屏时移动按钮的程序,在Release调试下可以通过,但在debug调试下出现如下错误rnRun-Time Check Failure #2 - Stack around the variable 'dy' was corrupted.请各位大侠帮忙!rn出错代码如下: rn int cx=::GetSystemMetrics(SM_CXSCREEN); rn int cy=::GetSystemMetrics(SM_CYSCREEN); rn CRect rtClient,rtBtn[9],rtBtn1,rtBtn2;rn int lx1,ly1,dx1,dy1,lx2,ly2,dx2,dy2,lx[9],ly[9],dx[9],dy[9];rn CWnd *pWnd[]=GetDlgItem(IDC_A),GetDlgItem(IDC_B),GetDlgItem(IDC_C),GetDlgItem(IDC_D),rn GetDlgItem(IDC_RIGHT),GetDlgItem(IDC_FALSE),GetDlgItem(IDC_FIRST),rn GetDlgItem(IDC_BACKTRACK),GetDlgItem(IDC_NEXT),GetDlgItem(IDC_LAST); rn GetClientRect(&rtClient); //获得对话框客户区屏幕坐标 rn ClientToScreen(&rtClient); //映射为屏幕坐标 rn rn for(int i=0;i<=9;i++)rn rn pWnd[i]->GetWindowRect(&rtBtn[i]); //获得button屏幕坐标rn lx[i]=rtBtn[i].Width(); //button长度 rn ly[i]=rtBtn[i].Height(); //button高度 rn dx[i]=rtClient.left+rtBtn[i].left; //离右边框的距离 rn dy[i]=rtClient.bottom-rtBtn[i].bottom; //离底边框的距离 rn pWnd[i]->MoveWindow(CRect(CRect(cx-dx[i]-lx[i],cy-ly[i]-dy[i],cx-dx[i],cy-dy[i])));//移动buttonrn
实在没辙了,请大家帮忙:Run-Time Check Failure #2 ……
今天第一次用VC++ !rnrn大家帮我看看以下代码,在某目录下查找文件数目时为什么会出现如下错误提示:rnrnRun-Time Check Failure #2 - stack around the variable 'filename' was corruptedrnrn代码如下:rnbool CBrowseDir::BrowseDirrn(const char *dir,const char *filespec)rnrnrn //tryrn _chdir(dir);rnrn //首先查找dir中符合要求的文件rn long hFile;rn _finddata_t fileinfo;rnrn if ((hFile=_findfirst(filespec,&fileinfo)) != -1)rn dorn rn //检查是不是目录rn //如果不是,则进行处理rn if (!(fileinfo.attrib & _A_SUBDIR))rn rn char filename[_MAX_PATH];rn strcpy(filename,dir);rn strcat(filename,fileinfo.name);rnrn CStdioFile file;rn CString string;rnrn if(file.Open(filename,CFile::modeRead))rn rn while(file.ReadString(string))rn rn if(string.Find("TEL=") == 0)rn break;rn rn rn rn file.Close();rn rnrn strcat(filename,"\r\n");rn strcat(filename,string);rnrn ProcessFile(filename);rn rn while (_findnext(hFile,&fileinfo) == 0);rnrn _findclose(hFile);rn rnrn //查找dir中的子目录rn //因为在处理dir中的文件时,派生类的ProcessFile有可能改变了rn //当前目录,因此还要重新设置当前目录为dir。rn //执行过_findfirst后,可能系统记录下了相关信息,因此改变目录rn //对_findnext没有影响。rn _chdir(dir);rnrn if ((hFile=_findfirst("*.*",&fileinfo)) != -1)rn rn dorn rn //检查是不是目录rn //如果是,再检查是不是 . 或 .. rn //如果不是,进行迭代rn if ((fileinfo.attrib & _A_SUBDIR))rn rn if (strcmp(fileinfo.name,".") != 0 && strcmprn (fileinfo.name,"..") != 0)rn rn char subdir[_MAX_PATH];rn strcpy(subdir,dir);rn strcat(subdir,fileinfo.name);rn strcat(subdir,"\\");rn ProcessDir(subdir,dir);rn if (!BrowseDir(subdir,filespec))rn return false;rn rn rn while (_findnext(hFile,&fileinfo) == 0);rn _findclose(hFile);rn rn //catch(...)rn // return false;rn //rn return true;rnrn
Run-Time Check Failure #2 - Stack around the variable 'tmp' was corrupted怎么办?
[code=c]rn#define _CRT_SECURE_NO_DEPRECATErn#includern#define MAX_SIZE 10rnrntypedef struct _Quern char value[MAX_SIZE];rn char head, tail, count;rn Que;rnrnvoid initQ(Que * q)rnrn char i;rn for (i = 0; i < MAX_SIZE; i++)rn rn q->value[i] = 0;rn rn q->head = q->tail = q->count = 0;rnrnrnchar isEmpty(Que * q)rnrn if(q->count==0&&q->head==q->tail) return 1;rn else return 0;rnrnrnchar isFull(Que * q)rnrn if(q->count!=0&&q->head==q->tail) return 1;rn else return 0;rnrnrnchar enQ(Que * q, char value)rnrn if(isFull(q)) return 0;rn q->value[q->head] = value;rn q->head++;rn if(q->head==MAX_SIZE) q->head = 0;rn q->count++;rn return 1;rnrnrnchar deQ(Que * q, char * value)rnrn if(isEmpty(q)) return 0;rn *value = q->value[q->tail];rn q->tail++;rn if(q->tail==MAX_SIZE) q->tail = 0;rn q->count--;rn return 1;rnrnrnint main()rnrn Que q;rn char tmp,i;rn initQ(&q);rn for(i=0;i<4;i++)rn rn scanf("%d", &tmp);rn enQ(&q, tmp);rn rn rn while(!isEmpty(&q))rn rn deQ(&q, &tmp);rn printf("%d\n", tmp);rn rn rn return 0;rnrn[/code]rn[img=https://img-bbs.csdn.net/upload/201509/21/1442847190_367328.jpg][/img]rn程序如上所示,一个简单的静态顺序表,出问题了。rn网上说是由于数组越界或栈被破坏造成的,可是tmp变量就不是数组啊!就取了下它的地址?rn如果是栈被破坏,又是怎么被破坏的呢?
Run-Time Check Failure #2 - Stack around the variable 'bmih' was corrupted
[b]很抱歉,这个需要错误检查,所以麻烦给位看看代码rn主要的源代码[/b]rn[code=c] HWND hWnd = pDlg->m_hWnd;rn HDC hdcTemp = pDlg->GetDC()->m_hDC;rn HDC m_hdcMemory = CreateCompatibleDC(hdcTemp);rn rn BYTE *pBits;rn BITMAPINFOHEADER bmih;//初始化bmih是BITMAPINFOHEADER类型rn ZeroMemory(&bmih,sizeof(BITMAPINFO)); rn //SecureZeroMemory(&bmih,sizeof(BITMAPINFO));//此处bmih是pvoid类型rn rn bmih.biSize = sizeof(BITMAPINFOHEADER);rn bmih.biWidth = nWidth;rn bmih.biHeight = nHeight;rn bmih.biPlanes = 1 ;rn bmih.biBitCount = 32;rn bmih.biCompression = BI_RGB;rn bmih.biSizeImage = 0 ;rn bmih.biXPelsPerMeter = 0 ;rn bmih.biYPelsPerMeter = 0 ;rn bmih.biClrUsed = 0 ;rn bmih.biClrImportant = 0 ;rn HBITMAP hBitMap = CreateDIBSection(NULL,(BITMAPINFO*)&bmih,0,(VOID**)&pBits,NULL,0);//此处bmih是BITMAPINFO*类型rn //============================================================================================rn SelectObject(m_hdcMemory,hBitMap);rn[/code]rn[b]以下是调用的类型定义[/b]rn[code=c]void ZeroMemory(rn [in] PVOID Destination,rn [in] SIZE_T Lengthrn);[/code]rn[code=c]typedef struct tagBITMAPINFO rn BITMAPINFOHEADER bmiHeader;rn RGBQUAD bmiColors[1];rn BITMAPINFO[/code]rn[code=c]typedef struct tagBITMAPFILEHEADER rn WORD bfType;rn DWORD bfSize;rn WORD bfReserved1;rn WORD bfReserved2;rn DWORD bfOffBits;rn BITMAPFILEHEADER[/code]
Run-Time Check Failure #2 - Stack around the variable 'mysql' was corrupted.
int main() rn rn rn rn MYSQL mysql; rn mysql_init(&mysql);rn cout<<"mysql init succeed!"<
Run-Time Check Failure #2 - Stack around the variable 'n' was corrupted
源程序如下:rn#includernint main()rnrn short n;rn printf("Enter a number:\n");rn scanf("%d",&n);rn printf("%x\n",n);rnrnreturn 0;rnrnrn我用的是vs2010,生成exe时没有出错,运行的时候输入一个数字,比如-1,然后就会出现一个标题为microsoft visual c++ debug library的提示窗口,说Run-Time Check Failure #2 - Stack around the variable 'n' was corrupted。当我不选中止运行而选ignore,结果为ffff却是正确的,这是为什么?还有我把上面的short n 改为int n就不会出现上述出错提示窗口,这和定义的数据类型有什么关系吗?rn
[MFC] Run-Time Check Failure #2 - Stack around the variable 'InitCtrls' was corrupted.
Debug模式下运行时,退出程序出现如下异常rnrnRun-Time Check Failure #2 - Stack around the variable 'InitCtrls' was corrupted.rnrnInitCtrls在代码中定义为:rnrnrn// InitCommonControlsEx() is required on Windows XP if an applicationrn// manifest specifies use of ComCtl32.dll version 6 or later to enablern// visual styles. Otherwise, any window creation will fail.rnINITCOMMONCONTROLSEX InitCtrls;rnInitCtrls.dwSize = sizeof(InitCtrls);rn// Set this to include all the common control classes you want to usern// in your application.rnInitCtrls.dwICC = ICC_WIN95_CLASSES;rnInitCommonControlsEx(&InitCtrls);rnrnCWinApp::InitInstance();rnrnAfxEnableControlContainer();rnrnrn以上是MFC默认生成的代码,但是出现错误,请问是什么原因导致的错误,已经如何解决,网上该问题出现的比较少,请达人明示rnrnrnrnrnrn
Run-Time Check Failure #2 - Stack around the variable 'dlg' was c
我在MFC里边的rnrnclass CxxxDlg : public CDialogrnrnrnpublic:rnrnrn下边,加任何一个定义,都会提示rnrn[color=#FF0000]Run-Time Check Failure #2 - Stack around the variable '[color=#0000FF]dlg[/color]' was corrupted.[/color]rnrn找了半天,都没找到想类似的问题!rn总之一定义CString 就出错,无论名字如何!rnrnrn[color=#FF0000]关闭的时候才会提示[/color]rnrnrnrn大大,求答案
为什么提示此错误?Run-Time Check Failure #2
在vs2005下rn结构体定义:rntypedef struct rnrn wstring strGroup; rn wstring strParticiple; rn BYTE GroupLen; rn BYTE DiffMeanStep; rnONE_LINE_INFO;rnrnvoid MyClass::AnalyzeOneLineData(ONE_LINE_INFO *pOneLineData,TCHAR*pStrLineData)rnrn wstring strLineData,strFirstPart;rn wstring::size_type idx,pos;rn WORD Step;rnrn Step = 0;rn strLineData = pStrLineData;rnrn idx = strLineData.find_first_of('(',0);rnrn pOneLineData->strGroup = strLineData.substr(0,idx);rnrn pos = strLineData.find_first_of(DIFFMEAN_STEP_FLAG,idx);rnrn strFirstPart = strLineData.substr(idx+1,pos-idx-1);rnrn _stscanf_s(strFirstPart.c_str(),_T("%d"), &Step);rnrn idx = pos;rn pos = strLineData.find_first_of(')',idx);rn rn pOneLineData->strParticiple = strLineData.substr(idx+1,pos-idx-1);rnrn if (m_ParticipleStrMaxLenstrParticiple.length()+1) rn rn m_ParticipleStrMaxLen = pOneLineData->strParticiple.length()+1;rn rnrn pOneLineData->GroupLen = pOneLineData->strGroup.length();rnrn if (m_GroupStrMaxLen < pOneLineData->GroupLen+1)rn rn m_GroupStrMaxLen = pOneLineData->GroupLen+1;rn rnrn pOneLineData->DiffMeanStep = Step;rnrnrnpStrLineData 的格式: 12个人(3,12 个)rn程序运行完pOneLineData->DiffMeanStep = Step;后在离开次函数时弹出错误提示:rnRun-Time Check Failure #2 - Stack around the variable 'Step'was corrupted.rn请教高人这是怎么回事?在vc6.0下却没有问题。rn多谢!
Run-Time Check Failure #2 - Stack around the variable 'ch' was corrupted.
读取一系列的图片rnchar ch[7];rnfor (int i=0; i<=26; i++)rnrn sprintf(ch, "b%d.bmp", i);rn pBitmap[i] = new CBitmap;rn pBitmap[i]->m_hObject = (HBITMAP) LoadImage(NULL, ch, IMAGE_BITMAP,rn 640,160 ,LR_LOADFROMFILE);rnrn设置断点,调试,每次到了26,然后再调试,就出现了问题:rn“Run-Time Check Failure #2 - Stack around the variable 'ch' was corrupted.”rn请问这是啥意思?rnrnPS:用google搜了一下,发现有人遇到过同样的问题,不过是E文的帖子,看不懂~~~,要学好E文呀~~~
Run-Time Check Failure #2 - Stack around the variable 'B' was corrupted.
[code=C/C++]#includernusing std::cout;rnusing std::endl;rnrnvoid main()rnrn const int n=8; const int k=5;rn int i,j;rn int A[]=2,5,3,0,2,3,0,3;rn int C[k+1]=0;rn int B[n]=0;rn rn for(j=0;j=0;j--)rn rn B[C[A[j]]] = A[j];rn C[A[j]] = C[A[j]]-1;rn rn rn for(i=0;i
Run-Time Check Failure #2 - Stack around the variable 'FCount' was corrupted.????
写了一访问数据的函数,执行SQL语句后就了出现上面的错误,请问是怎么回事啊。
相关热词 c#部署端口监听项目、 c#接口中的属性使用方法 c# 昨天 c#func链接匿名方法 c#怎么创建文件夹 c#从键盘接收空格 c#da/ad c#部门请假管理系统 c#服务器socket c# 默认的访问修饰符