关于c++输出参数问题。这个参数怎么初始化

C++语言 码拜 8年前 (2016-09-11) 2781次浏览
调用第三方dll文件,里面有大量输出参数。调试的时候说是未初始化。

void MyDlg::OnEnroll()
{
	/*HANDLE nHand;*/
	CString str;
	int ret;
	char pszErrorInfo[256];
	int i = 0;
	//unsigned char UserID[1]=NULL;
	CFile fp;

	unsigned char* pFeatureData;

	HINSTANCE hInst = LoadLibrary("ID_Fpr.DLL");
	HINSTANCE hInst1 = LoadLibrary("ID_FprCap.DLL");
	unsigned char cScannerType=GetDevice();
	OnBeginCap();//10准备采集图像
	int nChannel=GetDeviceCount(); 
	typedef int (WINAPI *MYFUNC)();
 // 获取函数地址
  MYFUNC fun=(MYFUNC)GetProcAddress(hInst, "FP_Begin");
   ret=fun(); //初始化操作
   if (ret!=1)
	{   
		 typedef int(WINAPI *Eor)(int ,char*);
			Eor eor=(Eor)GetProcAddress(hInst1,"LIVESCAN_GetErrorInfo");
			eor(ret,pszErrorInfo);
			str.Format("%s",pszErrorInfo);
		    m_text = str;
		    UpdateData(false);
	}
	m_text = "请按压手指...";
	UpdateData(false);

	int X,Y=0, W,H=0;
	typedef int(WINAPI *MYFUN1)(int,int*,int*,int*,int*);
	MYFUN1 fun1=NULL;
	fun1=(MYFUN1)GetProcAddress(hInst1,"LIVESCAN_GetCaptWindow");
	ret = fun1(nChannel,&X,&Y,&W,&H);
	if (ret!=1)
	{
		 typedef int(WINAPI *Eor)(int ,char*);
			Eor eor=(Eor)GetProcAddress(hInst1,"LIVESCAN_GetErrorInfo");
			eor(ret,pszErrorInfo);
			str.Format("%s",pszErrorInfo);
		    m_text = str;
		    UpdateData(false);
	}
	for (i=0;i<3;i++)
	{   
		typedef int(WINAPI *RAW)(int,unsigned char*);
		RAW raw=(RAW)GetProcAddress(hInst1,"LIVESCAN_GetFPRawData");
		ret = raw(nChannel,imageRAW);//获取一帧RAW图像
		if (ret!=1)
		{
			typedef int(WINAPI *Eor)(int ,char*);
			Eor eor=(Eor)GetProcAddress(hInst1,"LIVESCAN_GetErrorInfo");
			eor(ret,pszErrorInfo);
			str.Format("%s",pszErrorInfo);
		    m_text = str;
		    UpdateData(false);
		}
		/*typedef int(WINAPI *MYFUN2)(int,unsigned char*);
		MYFUN2 fun2=(MYFUN2)GetProcAddress(hInst1,"LIVESCAN_GetFPBmpData");
		fun2(nChannel,imageBMP);

		ImgData2BMP();*/
		HBITMAP hbitmap = BufferToHBITMAP(GetDC()->m_hDC,imageBMP);
		DisBMPByHBitmap(GetDlgItem(IDC_BMPF1+i)->m_hWnd,hbitmap,1);
		DeleteObject(hbitmap);

		memset(featurebuf1+i*512, 0, 512);


		memcpy(image, imageRAW,W*H);


	    typedef int(WINAPI *MYFUN3)(unsigned char,unsigned char,unsigned char*,unsigned char*);
		MYFUN3 fun3=(MYFUN3)GetProcAddress(hInst," FP_FeatureExtract");
	    ret=fun3(cScannerType, 0x11, (featurebuf1+i*512) ,(pFeatureData+i));		 
	 	str.Format("Finger%d.fea",i);
		fp.Open(str,CFile::modeWrite|CFile::modeCreate,NULL);
		fp.Write(featurebuf1+i*512,512);
    	fp.Close();
        unsigned char Q = 0L;
		if (ret)
		{typedef int(WINAPI *Eor)(int ,char*);
			Eor eor=(Eor)GetProcAddress(hInst1,"LIVESCAN_GetErrorInfo");
			eor(ret,pszErrorInfo);
			str.Format("%s",pszErrorInfo);
		    m_text = str;
		    UpdateData(false);
		}
		m_text = "请再次按压手指...";
		UpdateData(false);
	}



	unsigned char pFeatDate[3][512] = {0};
	float * pfSimilarity;
	memcpy(pFeatDate[0], featurebuf1, 512);
	memcpy(pFeatDate[1], featurebuf1+512, 512);
	memcpy(pFeatDate[2], featurebuf1+1024, 512);
	typedef int(*MYFUN4)(unsigned char*,unsigned char*,float *);
	MYFUN4 fun4=(MYFUN4)GetProcAddress(hInst,"FeatureMatch");
	int MATCH0= fun4(pFeatDate[0],pFeatDate[1],pfSimilarity);
	int MATCH1= fun4(pFeatDate[1],pFeatDate[2],pfSimilarity);
	int MATCH2= fun4(pFeatDate[0],pFeatDate[2],pfSimilarity);
	int avg=(MATCH0+MATCH1+MATCH2)/3;
	if(avg>0.8){
	   unsigned char* pnScore;
	   typedef int(*MYFUN5)(unsigned char*,unsigned char*);
	   MYFUN5 fun5=(MYFUN5)(hInst,"FP_GetQualityScore");
	   int Score0=fun5(featurebuf1,pnScore);
       int Score1=fun5((featurebuf1+1*512),pnScore);
	   int Score2=fun5((featurebuf1+2*512),pnScore);
	   unsigned char * pCompressedImgBuf[1024] ;
	   unsigned char strBuf[256] ;
	   typedef int(*MYFUN6)(unsigned char,unsigned char,unsigned char,unsigned char*,int,unsigned char*,unsigned char);
	   MYFUN6 fun6=(MYFUN6)(hInst,"FP_Compress");
	   unsigned char cEnrolResult=0x1;
	   int nCompressRatio=4;
	   unsigned char *pFingerImgBuf;
	   if(Score0<Score1&&Score1<Score2||Score1<Score0&&Score0<Score2){
		 
		  fun6(cScannerType, cEnrolResult, 0x11 ,(featurebuf1+2*512),nCompressRatio, pCompressedImgBuf[1024], strBuf[256] );
	      typedef int(*MYFUN7)(unsigned char*,unsigned char*,unsigned char);
	      MYFUN7 fun7=(MYFUN7)(hInst,"FP_Decompress"); 
		  fun7( pCompressedImgBuf[1024] ,pFingerImgBuf,strBuf[256]);
		  fp.Open("Finger.bmp",CFile::modeWrite|CFile::modeCreate,NULL);
		  fp.Write(pCompressedImgBuf,512);
	      fp.Close();
	  }
	  if(Score0<Score2&&Score2<Score1||Score2<Score0&&Score0<Score1){
	      fun6(cScannerType, cEnrolResult, 0x11 ,(featurebuf1+1*512),nCompressRatio, pCompressedImgBuf[1024], strBuf[256] );
          typedef int(*MYFUN7)(unsigned char*,unsigned char*,unsigned char);
	      MYFUN7 fun7=(MYFUN7)(hInst,"FP_Decompress"); 
		  fun7( pCompressedImgBuf[1024] ,pFingerImgBuf,strBuf[256]);
		  fp.Open("Finger.bmp",CFile::modeWrite|CFile::modeCreate,NULL);
		  fp.Write(pCompressedImgBuf,512);
	      fp.Close();
	  }
	  if(Score1<Score2&&Score2<Score0||Score2<Score1&&Score1<Score0){
	      fun6(cScannerType, cEnrolResult, 0x11 ,(featurebuf1),nCompressRatio, pCompressedImgBuf[1024], strBuf[256] );
          typedef int(*MYFUN7)(unsigned char*,unsigned char*,unsigned char);
	      MYFUN7 fun7=(MYFUN7)(hInst,"FP_Decompress"); 
		  fun7( pCompressedImgBuf[1024] ,pFingerImgBuf,strBuf[256]);
		  fp.Open("Finger.bmp",CFile::modeWrite|CFile::modeCreate,NULL);
		  fp.Write(pCompressedImgBuf,512);
	      fp.Close();
	  }

关于c++输出参数问题。这个参数怎么初始化
这是报错内容  是本人未初始化。在生成过程中,
1>e:\kaifa\viewdemo4\viewdemo4\mydlg.cpp(581): warning C4700: 使用了未初始化的局部变量“pFeatureData”
1>e:\kaifa\viewdemo4\viewdemo4\mydlg.cpp(609): warning C4700: 使用了未初始化的局部变量“pfSimilarity”
1>e:\kaifa\viewdemo4\viewdemo4\mydlg.cpp(617): warning C4700: 使用了未初始化的局部变量“pnScore”
1>e:\kaifa\viewdemo4\viewdemo4\mydlg.cpp(629): warning C4700: 使用了未初始化的局部变量“strBuf”
1>e:\kaifa\viewdemo4\viewdemo4\mydlg.cpp(629): warning C4700: 使用了未初始化的局部变量“pCompressedImgBuf”
1>e:\kaifa\viewdemo4\viewdemo4\mydlg.cpp(632): warning C4700: 使用了未初始化的局部变量“pFingerImgBuf”
1>e:\kaifa\viewdemo4\viewdemo4\mydlg.cpp(668): warning C4700: 使用了未初始化的局部变量“pnScore”
1>e:\kaifa\viewdemo4\viewdemo4\mydlg.cpp(680): warning C4700: 使用了未初始化的局部变量“strBuf”
1>e:\kaifa\viewdemo4\viewdemo4\mydlg.cpp(680): warning C4700: 使用了未初始化的局部变量“pCompressedImgBuf”
1>e:\kaifa\viewdemo4\viewdemo4\mydlg.cpp(683): warning C4700: 使用了未初始化的局部变量“pFingerImgBuf”
上面这些全是输出参数,本人应该怎么做?简直迷茫

解决方案

20

unsigned char* pFeatureData;
你的这个pFeatureData没有初始化

20

需要分配空间,就malloc或new,不需要空间的就弄成NULL

5

unsigned char pFeatureData[1024];

15

unsigned char* pFeatureData[1024];//这句话只是声明了一个1024元素的数组,每个元素中可以保存一个地址,从某个地址开始准备保存一系列char;但这些地址没设初值,即没向操作系统申请一段固定字节长度的可用内存,操作系统返回给你一个起始地址,你再将这个起始地址填写到某个元素中。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明关于c++输出参数问题。这个参数怎么初始化
喜欢 (0)
[1034331897@qq.com]
分享 (0)