您的位置:首页 > 移动开发

DS-4000系列板卡SDK and Demo Version 5.1 中的错误

2011-05-09 16:34 781 查看


错误定位

1,工程名字:Src/NetDemoSource/NetServerDemo 工程名: HKVision。服务器端的demo。
2,文件和错误定位:
1)中断出现在HKVision.cpp中86行的语句: int nResponse = dlg.DoModal();
BOOL CHKVisionApp::InitInstance()
{
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
//  of your final executable, you should remove from the following
//  the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls();			// Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif
int w = GetSystemMetrics(SM_CXSCREEN);
int h = GetSystemMetrics(SM_CYSCREEN);
if((w < 1024)||(h < 768)){
AfxMessageBox("You must set display resolution to 1024x768 or more in order to run the program/n");
return FALSE;
}
CHKVisionDlg dlg;
m_pMainWnd = &dlg;
RegisterLogRecordCallback(LogRecordFunc, &dlg);
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
//  application, rather than start the application's message pump.
return FALSE;
}
 
2)调试跟踪到了HKVisionDlg.cpp中函数BOOL CHKVisionDlg::OnInitDialog()中语句:
 
if (!MP4_ServerStart(&videoinfo))

{

MessageBox("error","error",MB_OK);

}

具体位置在459行。

 

3)最终错误定位在函数:
int __cdecl StreamDirectReadCallback(ULONG channelNum,void *DataBuf,DWORD Length,int frameType,void *context)
该函数中的:
 
CHKVisionDlg *pMain = (CHKVisionDlg *)AfxGetMainWnd();
pMain->GetDlgItem(IDC_BPS)->SetWindowText((LPCTSTR)str);
 

 

错误分析:

MP4_ServerStart时候,调用回调函数StreamDirectReadCallback函数,估计(源码未公开)是专门开了一个线程调用StreamDirectReadCallback函数。在StreamDirectReadCallback函数中使用了AfxGetMainWnd()。而AfxGetMainWnd函数返回null,可以google “AfxGetMainWnd null” "AfxGetMainWnd 失效"。
http://topic.csdn.net/u/20100430/10/1FF4D768-E1A3-4B4D-8F77-0EFB2A3DFD08.html  

解决方法:

将pMain作为全局的CHKVisionDlg*指针,初始化为NULL,在CHKVisionDlg::OnInitDialog 中,函数结尾处添加:
pMain = this;
最后再StreamDirectReadCallback中可以直接使用pMain了。。。
 

后记

错误定位最为痛苦。步骤1,到步骤2,再到步骤3的跟踪很需要想象力,直接F11根本跟不过去,一个下午才解决。所以写出来~,跟大家分享~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐