MFC中CString转const char *

CString转const char *是一件麻烦事,但是在做项目中经常遇到,所以这里做个笔记。

//CString转const char* 麻烦
		LPCTSTR p=pathName.GetBuffer();
		DWORD dwMinSize;
		dwMinSize=WideCharToMultiByte(CP_ACP,NULL,p,-1,NULL,0,NULL,FALSE);
		char * filename=new char[dwMinSize];
		WideCharToMultiByte(CP_OEMCP,NULL,p,-1,filename,dwMinSize,NULL,FALSE);
		//返回播放暂停时的初始位置
		CvCapture* capture = cvCreateFileCapture(filename);
		cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, t_FrameNumberStart);
		IplImage* Img;
		Img=cvQueryFrame(capture);
		CMainFrame* pFrame = (CMainFrame *)(AfxGetApp()->m_pMainWnd);  
		CVideoDectView* pViw = (CVideoDectView*)pFrame->GetActiveView();
		pViw->m_VideoPlayCtrl.ShowIplImage((VARIANT* )Img, 0, 0, 1);


你可能感兴趣的:(char,Const,CString)