vc ++ dll某些功能不起作用 [英] vc++ dll some function are not working

查看:89
本文介绍了vc ++ dll某些功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

头文件

header file

#include "StdAfx.h"
#include "MainFrm.h"
#include "DlgView.h"
//#include "ViewImage.h"
//#include "DlgSelectResolution.h"
#include "afx.h"
#include "iostream"
#include "fstream"
using namespace std;

#ifdef ISILCARD_EXPORTS
#define ISILCARD_API extern "C"  __declspec(dllexport) 
#else 
#define ISILCARD_API extern "C"  __declspec(dllimport) 
#endif

ISILCARD_API ISILERR_CODE __stdcall ISIL_Card_RegEncode2Callback(CardEncode2CallBack funCallBack,void *pContext);

#define TRUE    1

CFile   m_hFileV      ;
CFile   m_hFileA;
unsigned int m_nChannelID;
long    m_nWriteAudioDataSize;
int nChannel;
bool    m_bNeedIFrame ;
unsigned char	m_cWriteSPSpps ;

BOOL   g_bRecordToTwoFile1= 1;
DWORD   m_dwPreTime   ;
int     m_nFpsPrint ;
int     m_nFrameCount ;
bool			m_bOpenEncode[MAX_CHANNEL];
unsigned int  i;
//HANDLE			g_hChannel[MAX_CHANNEL] ;

//typedef void (_stdcall *CardEncode2CallBack)(unsigned int nChannel,ISIL_ENCODE_DATA *pEncData,void *pContext);


class MainClass
{
private:
	CDlgView		*m_pDlgView[MAX_VIEW_TYPE_NUM];
//	CDlgView		*m_pDlgView[MAX_VIEW_TYPE_NUM];
	MainClass*		m_pViewWnd[MAX_CHANNEL] ;
//	bool			m_bOpenEncode[MAX_CHANNEL];
	int				m_nViewObj  ;
	unsigned int m_nChannelID;
	
public:
	MainClass(void);
	~MainClass(void);
public:
	//CFile   m_hFileV1      ;
	
	CFile   m_hFileA      ; 
	//DWORD   m_dwPreTime   ;
	int     m_nFpsPrint ;
	int     m_nFrameCount ;
	
public:
	
	int __stdcall StartCard();
	int __stdcall StartChannel(int ChannelID);
	int __stdcall SetChannalEncode(HANDLE nChID, int streamType);
	int __stdcall RegCallBack();
	void Invalidate();
	void	OpenFile1(BOOL bMainStream);
	
	//void	OpenFile(DWORD strFileName);

	
	int __stdcall CB_CardEncode2(unsigned int nChannel,ISIL_ENCODE_DATA *pEncData,void *pContext);
	int __stdcall CB_CardReadEncode(unsigned int nChannel,void *pContext);
	void	WriteBareStreamV1(unsigned int nChannel,unsigned char cDataType,void* pBuffer, unsigned long lBufSize);
	int WriteBareStream(unsigned int nChannel,ISIL_ENCODE_DATA *pEncData);
	void	WriteBareStreamV(unsigned char cDataType,void* pBuffer, unsigned long lBufSize);
	//void	WriteBareStreamV(unsigned char cDataType,void* pBuffer, unsigned long lBufSize);
	void	WriteBareStreamA1(void* pBuffer, unsigned long lBufSize);
	void	WriteBareStreamA(unsigned int nChannel,void* pBuffer, unsigned long lBufSize);
	//void	WriteBareStreamA(void* pBuffer, unsigned long lBufSize);
	//ISIL_Card_StartCapEncode(HANDLE hChannel, bool bSub = false);
	//void OpenFile1(DWORD strFileName);
	int __stdcall  StartRecording(int nChannel,DWORD strfileName);
	
};
////////////////////////////////////////





cpp文件








cpp file




#include "stdafx.h"
#include "afxwin.h"
#include <math.h>
#include "MainClass.h"
#include "CardDemo.h"
#include <io.h>
//#include "DlgView.h"
//#include "ViewImage.h"
//#include "DlgSelectResolution.h"
#include <iostream> 
#include <fstream>
extern "C"
{
MainClass::MainClass(void)
{
}
/////////////////////////////////////////////////////////////////
void WriteBareStreamV(unsigned char cDataType,void* pBuffer, unsigned long lBufSize)
{
	
	DWORD dwTime = timeGetTime() ;
	if ( dwTime - m_dwPreTime > 1000 )
	{
		m_dwPreTime = dwTime ;
		m_nFpsPrint = m_nFrameCount ;
		//this->Invalidate();
		m_nFrameCount = 0 ;	}
	else
	{
		if( cDataType == ISIL_DATA_TYPE_MAIN_I || cDataType == ISIL_DATA_TYPE_MAIN_P|| cDataType == ISIL_DATA_TYPE_MAIN_B ||
			cDataType == ISIL_DATA_TYPE_SUB_I  || cDataType == ISIL_DATA_TYPE_SUB_P || cDataType == ISIL_DATA_TYPE_SUB_B )
		{
 			m_nFrameCount++;
		}
	}
	if(m_hFileV.m_hFile != NULL)
	{
		if( ( m_cWriteSPSpps == (ISIL_DATA_TYPE_MAIN_SPS|ISIL_DATA_TYPE_MAIN_PPS) ) ||
			( m_cWriteSPSpps == (ISIL_DATA_TYPE_SUB_SPS|ISIL_DATA_TYPE_SUB_PPS) ) )
		{
			if(m_bNeedIFrame)
			{
				if(cDataType == ISIL_DATA_TYPE_MAIN_I || cDataType == ISIL_DATA_TYPE_SUB_I)
				{
					m_hFileV.Write(pBuffer, lBufSize);
					m_bNeedIFrame = false ;
				}
			}
			else
			{
				m_hFileV.Write(pBuffer, lBufSize);
			}
			return ;
		}
		if(cDataType == ISIL_DATA_TYPE_MAIN_SPS || cDataType == ISIL_DATA_TYPE_SUB_SPS)
		{
			m_cWriteSPSpps = cDataType ;
			m_hFileV.Write(pBuffer, lBufSize);
			return ;
		}
		if(cDataType == ISIL_DATA_TYPE_MAIN_PPS || cDataType == ISIL_DATA_TYPE_SUB_PPS)
		{
			if( (m_cWriteSPSpps == ISIL_DATA_TYPE_MAIN_SPS) || (m_cWriteSPSpps == ISIL_DATA_TYPE_SUB_SPS))
			{
				m_cWriteSPSpps |= cDataType;
				m_hFileV.Write(pBuffer, lBufSize);
 				return ;
			}
		}
	}
}//////////////////////tn///////////////////



void WriteBareStreamV1(unsigned int nChannel,unsigned char cDataType,void* pBuffer, unsigned long lBufSize)
{
	if( nChannel < g_nChannelTotal )
	{
		WriteBareStreamV(cDataType,pBuffer,lBufSize);
	}
}
void WriteBareStreamA1(void* pBuffer, unsigned long lBufSize)
{
	if(m_hFileA.m_hFile != NULL)
	{
		m_hFileA.Write(pBuffer, lBufSize);
		m_nWriteAudioDataSize += lBufSize;
	}
}
void WriteBareStreamA(unsigned int nChannel,void* pBuffer, unsigned long lBufSize)
{
	if( nChannel < g_nChannelTotal )
		WriteBareStreamA1(pBuffer,lBufSize);
}

/////////////////////////////////
void Invalidate()
{
	BOOL bErase=1;
}
//void	WriteBareStreamA(void* pBuffer, unsigned long lBufSize);

int WriteBareStream(unsigned int nChannel,ISIL_ENCODE_DATA *pEncData)
{
 	switch (pEncData->cDataType) 
	{
	case ISIL_DATA_TYPE_MAIN_SPS:
	case ISIL_DATA_TYPE_MAIN_PPS:
	case ISIL_DATA_TYPE_MAIN_I:
	case ISIL_DATA_TYPE_MAIN_P:
	case ISIL_DATA_TYPE_MAIN_B:
		WriteBareStreamV1(nChannel,pEncData->cDataType,pEncData->pBuffer, pEncData->lBufSize);
		break;
	case ISIL_DATA_TYPE_SUB_SPS:
	case ISIL_DATA_TYPE_SUB_PPS:
	case ISIL_DATA_TYPE_SUB_I:
	case ISIL_DATA_TYPE_SUB_P:
	case ISIL_DATA_TYPE_SUB_B:
		WriteBareStreamV1(nChannel,pEncData->cDataType,pEncData->pBuffer, pEncData->lBufSize);
		break;
	case ISIL_DATA_TYPE_A:
		if(g_bRecordToTwoFile1)
			WriteBareStreamA(nChannel,pEncData->pBuffer, pEncData->lBufSize);
		else
			WriteBareStreamV1(nChannel,pEncData->cDataType,pEncData->pBuffer, pEncData->lBufSize);
		break;
	}
	return 1;
}

__declspec(dllexport)  int __stdcall CB_CardEncode2(unsigned int nCh,ISIL_ENCODE_DATA *pEncData,void *pContext)
{
	////////////FILEcreate/////////
	FILE *P=fopen("c:/Record/TP5.txt","w");
	fprintf(P, "i am card encode2!!!");
    fclose(P);


	unsigned int nChannel = GetFactChannelIDEx(nCh);
	
	int x=WriteBareStream(nChannel,pEncData);
	return x;
	
}

__declspec(dllexport)  int __stdcall  CB_CardReadEncode(unsigned int nChannel,void *pContext)
{
	return 1;

}




void	OpenFile1(BOOL bMainStream)
{
	
 	if(m_hFileV.m_hFile != NULL)
	
	CreateDirectory("c:\\Record\\ ", NULL) ;
	char szFile[125];
	SYSTEMTIME st;
	GetLocalTime(&st);

	sprintf(szFile,"c:\\Record\\Main_CH%02d_Time%02d%02d%02d.h264",m_nChannelID+1,
						st.wHour, st.wMinute, st.wSecond);
		m_hFileV.Open(szFile, CFile::modeCreate|CFile::modeReadWrite);
}







/////////////////////////////////////////////////////////////////
__declspec(dllexport)  int __stdcall RegCallBack()
{
	//if(g_nCardTotal	== 0)
	//	return ;
	FILE *P=fopen("c:/Record/TP.txt","w");
	fprintf(P, "TESTING!!!");
    fclose(P);
	
	int i =ISIL_Card_RegEncode2Callback((CardEncode2CallBack)CB_CardEncode2,NULL);
	i= ISIL_Card_RegReadEncodeCallback((CardReadEncodeCallBack)CB_CardReadEncode, NULL);
	return i;
	
}

__declspec(dllexport)  int __stdcall StartCard()
{
	unsigned int  i ;
	
	unsigned int g_nCardTotal	= 0 ;
	unsigned int g_nChannelTotal = 0 ;
	ISIL_Card_Init() ;
//	if( ISIL_Card_Init() == ISIL_ERR_SUCCESS )
	{
		unsigned long lCardTotal = 0 ;
		if(ISIL_Card_GetCardCount(&lCardTotal) == ISIL_ERR_SUCCESS )
		{
			unsigned long lChannelTotal = 0 ;
 			if(ISIL_Card_GetChannelCount(&lChannelTotal) == ISIL_ERR_SUCCESS )
			{
				g_nCardTotal	= (unsigned int)lCardTotal;
				g_nChannelTotal = (unsigned int)lChannelTotal;
			}
		}
	}
	//	Êý¾ÝÖ¡µÄÆðʼʱ¼ä 
 	ISIL_VIDEO_STANDARD  vs[3];
	vs[0] = ISIL_VIDEO_STANDARD_NTSC ;
	vs[1] = ISIL_VIDEO_STANDARD_PAL ;
	vs[2] = ISIL_VIDEO_STANDARD_SECAM ;
	int nSel = 1;
	for (i=0; i<g_ncardtotal;>	{
		ISIL_Card_SetVideoStandard(i,vs[nSel]);
		ISIL_Card_SetAutoResetTime(i, 0);
	}

	return g_nChannelTotal;

	RegCallBack();
}



__declspec(dllexport) int __stdcall StartChannel(int ChannelID)
{
	HANDLE			g_hChannel = NULL ;

	int intStatus =ISIL_Card_OpenChannel(ChannelID, g_hChannel);
	

	ISIL_AUDIO_TYPE audioType[4];
	audioType[0]=ISIL_AUDIO_PCM;
//	audioType[1]=ISIL_AUDIO_ALAW;
//	audioType[2]=ISIL_AUDIO_ULAW;
	audioType[1]=ISIL_AUDIO_ADPCM; // 3->1
	int nSel = 0;
	ISIL_Card_SetAudioType(g_hChannel,audioType[nSel]);
	////////
	bool bHFlip = false;
	bool bVFlip = false;
	ISIL_Card_SetVideoFlip(g_hChannel, bHFlip, bVFlip);
	//
	int  nBrightness = 112; //Alice
	int  nContrast   = 128;
	int  nSaturation = 115; //Alice
	int  nHue		 = 128;	
	ISIL_Card_SetVideoPara(g_hChannel,  nBrightness,   nContrast,   nSaturation,   nHue);
	//
	ISIL_Card_SetEncPriority(g_hChannel,0);   //nPri: [0,3]      

	return intStatus;
}
__declspec(dllexport)  int __stdcall SetChannalEncode(HANDLE nChID, int streamType)
{
	int intStatus=ISIL_Card_SetStreamType(nChID,streamType,false);
	return intStatus;
}


__declspec(dllexport)  int __stdcall StartRecording(int nChannel,DWORD strfileName)
{
	


	OpenFile1(TRUE);

	if(ISIL_Card_StartCapEncode(g_hChannel[nChannel-1],true)== ISIL_ERR_SUCCESS)
	
		m_bOpenEncode[i] = true ;
	FILE *X=fopen("c:/Record/newfile.txt","w");
	fprintf(X, "I AM IN sTARTRECORDING!!!");
    fclose(X);
	
	return TRUE ;
}






MainClass::~MainClass(void)
{
}
}





我正在使用project function创建一个dll.有些功能正在运行,例如








i am creating a dll using project function.there are some function are working like




int __stdcall StartCard();
int __stdcall StartChannel(int ChannelID);
int __stdcall SetChannalEncode(HANDLE nChID, int streamType);



但无法使用某些功能



but not working some function

int __stdcall RegCallBack();
int __stdcall CB_CardEncode2(unsigned int nChannel,ISIL_ENCODE_DATA *pEncData,void *pContext);
int __stdcall CB_CardReadEncode(unsigned int nChannel,void *pContext);
void WriteBareStreamV1(unsigned int nChannel,unsigned char cDataType,void* pBuffer, unsigned long lBufSize);
int WriteBareStream(unsigned int nChannel,ISIL_ENCODE_DATA *pEncData);
void WriteBareStreamV(unsigned char cDataType,void* pBuffer, unsigned long lBufSize);
//void WriteBareStreamV(unsigned char cDataType,void* pBuffer, unsigned long lBufSize);
void WriteBareStreamA1(void* pBuffer, unsigned long lBufSize);
void WriteBareStreamA(unsigned int nChannel,void* pBuffer, unsigned long lBufSize);
//void WriteBareStreamA(void* pBuffer, unsigned long lBufSize);
//ISIL_Card_StartCapEncode(HANDLE hChannel, bool bSub = false);
//void OpenFile1(DWORD strFileName);
int __stdcall StartRecording(int nChannel,DWORD strfileName);


请帮助我,我在哪里走错了路.
请给我建议.
谢谢

[edit]已排序的代码块-OriginalGriff [/edit]



当编译代码CB_CardEncode2函数未读取时,表示控件未转到CB_CardEncode2
功能;
int __stdcall CB_CardEncode2(unsigned int nChannel,ISIL_ENCODE_DATA * pEncData,void * pContext);

请帮帮我.

谢谢......


Please help me and where am i going wrong way.
please give me suggation.
Thanks

[edit]Code blocks sorted - OriginalGriff[/edit]



when the compile the code CB_CardEncode2 function not read means control not goes to CB_CardEncode2
function;
int __stdcall CB_CardEncode2(unsigned int nChannel,ISIL_ENCODE_DATA *pEncData,void *pContext);

Please help me.

Thanks...............

推荐答案

FILE *P=fopen("c:/Record/TP.txt","w");


我认为这些路径分隔符不起作用.尝试使用''\\''.


I don''t think these path delimiters will work. Try ''\\'' instead.




也许是愚蠢的问题,但是您是否检查/更新了DLL的DEF文件?

Sasa


maybe stupid question, but did you check/update DEF file of your dll ?

Sasa


这篇关于vc ++ dll某些功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆