运行时检查失败#2,同时使用API​​保存图像帧

MSVS 2010,Windows 7

我正在使用API​​来访问相机function。

以下function显示一个框架并保存。

void DisplayThread::OnBufferDisplay( PvBuffer *aBuffer ) { mDisplayWnd->Display( *aBuffer ); //displaying frame //Now let us try to save the frame with name of the form %Y%m%d%H%M%S.bmp system("mkdir D:\\ABCD" ); struct tm *tm; int count; time_t t; char str_time[20]; t = time(NULL); tm = localtime(&t); strftime(str_time, sizeof(str_time), "%Y%m%d%H%M%S.bmp", tm); //name of the frame char name[1000]; //sufficient space sprintf(name,"%s",str_time); char path[]="D:\\ABCD"; strcat(path,name); //path =path+"\\"+name; // char* str=(char*)(void*)Marshal::StringToHGlobalAnsi(path); PvString lFilename( path ); PvString lCompleteFileName( lFilename ); PvBufferWriter lBufferWriter; //The following function saves image PvResult lResult = lBufferWriter.Store( aBuffer, lCompleteFileName, PvBufferFormatBMP ); } 

保存的bmp文件的名称格式为%Y%m%d%H%M%S.bmp

该程序构建完美,即使显示正确,但会弹出以下错误消息:

在此处输入图像描述

使用变量’name’进行内存分配似乎有问题。

但是我已经分配了足够的空间,即便如此我也收到了这个错误。

为什么会这样?

请告诉我是否需要更多信息来调试此信息。

注意: lBufferWriter.Store()返回的值为’OK’(表示缓冲区/帧写入成功),但没有保存文件。 我想这是因为我得到的运行时检查失败。

请帮忙。

您的path []数组大小为8,并且在连接后它太小而无法容纳字符串。 由于此路径变量位于堆栈上,因此它正在破坏堆栈。 因此,您的缓冲区应足够大,以容纳您想要放入其中的数据。

在您的情况下只需将行更改为:

 char path[1024]="D:\\ABCD";