本文介绍了如何从另一个C ++文件中的C ++文件调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个abc.cpp文件和abc.h文件.
在abc.cpp文件中,声明在myDLL.dll中定义的函数.

abc.h文件是..

I have a abc.cpp file and abc.h file.
In abc.cpp file declare functions which are defined in myDLL.dll.

abc.h file is..

#ifndef _DERMALOGFINGERCODE3_H_
#define _DERMALOGFINGERCODE3_H_

#include "ABCSDK_Definitions.h"
#include "ErrorCodes.h"
#include "BitmapInfoHeader.hpp"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/*! \brief type definition for the FC3 handle */
typedef void* FC3_t;
/*! \brief type definition for the template handle */
typedef FC3_t FC3Template_t;
/*! \brief type definition for the encode handle */
typedef FC3_t FC3Encode_t;
/*! \brief type definition for the match handle */
typedef FC3_t FC3Match_t;

DrmErrorCode_t DRMAPI FC3Initialize(const char* szReserved);

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // _DERMALOGFINGERCODE3_H_
//! \endgroup

ErrorCodes.h文件为

ErrorCodes.h file is

#ifndef _ERRORCODES_H_
#define _ERRORCODES_H_

#include <stddef.h>
typedef long DrmErrorCode_t;//DrmErrorCode_t is in ErrorCodes.h defined
#endif /* _ERRORCODES_H_*/


ABCSDK_Definitions.h文件为


ABCSDK_Definitions.h file is

#ifndef _DERMALOGSDK_DEFINITIONS_H_
#define _DERMALOGSDK_DEFINITIONS_H_

/*! \define DRMAPI
\brief a define for the calling convention for MS Windows.
*/
#ifndef DRMAPI
#if defined(WIN32) || defined(_WIN32)
#define DRMAPI __stdcall
#else
#define DRMAPI
#endif
#endif

//! property type enumeration
typedef enum { eLong, eDouble, eString } enumType_t;
//! property access enumeration
typedef enum { eNone, eIn, eOut,eInOut } enumAccess_t;
#endif // _DERMALOGSDK_DEFINITIONS_H_


BitmapInfoHeader.hppfile是


BitmapInfoHeader.hppfile is

#ifndef _BITMAPINFOHEADER_HPP_
#define _BITMAPINFOHEADER_HPP_

#ifdef WINCE
#define BI_RLE8       (1L)
#endif

#if !defined(WIN32) || defined(__CYGWIN__)
#define WINAPI
/* constants for the biCompression field */
#define BI_RGB        (0u)
#define BI_RLE8       (1u)
#define BI_RLE4       (2u)
#define BI_BITFIELDS  (3u)
#define BI_JPEG       (4u)
#define BI_PNG        (5u)

/* LONG must be defined as a 32 signed int.*/
#include <inttypes.h>
#ifndef DWORD
	typedef uint32_t DWORD;
#endif
#ifndef WORD
	typedef uint16_t WORD;
#endif
#ifndef BYTE
	typedef uint8_t BYTE;
#endif
#ifndef LONG
	typedef int32_t LONG;
#endif
#ifndef BOOL
	typedef int32_t BOOL;
#endif
#ifndef HMODULE
	typedef void* HMODULE;
#endif

typedef struct tagBITMAPINFOHEADER{
	DWORD        biSize;
	LONG         biWidth;
	LONG         biHeight;
	WORD         biPlanes;
	WORD         biBitCount;
	DWORD        biCompression;
	DWORD        biSizeImage;
	LONG         biXPelsPerMeter;
	LONG         biYPelsPerMeter;
	DWORD        biClrUsed;
	DWORD        biClrImportant;
} BITMAPINFOHEADER;

#endif /* WIN32 / CYGWIN */
#endif /* _BITMAPINFOHEADER_HPP_ */


现在abc.cpp文件是


Now abc.cpp file is

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <memory>
#if defined(WIN32)
#include <Windows.h>
#endif
#include "TutException.hpp"
#include "TutFile.hpp"
#include "TutBitmap.hpp"
#include "TutLoadLibrary.hpp"
#include "TutParams.hpp"

/* defines for system independence */
#if defined(WIN32)
	#define DERMALOG_LIBNAME "myDLL.dll" /* load the .dll file when using windows*/

#endif

#include "abc.h"

/* global handle for the dynamic library */
HMODULE g_hLib = NULL;
const char* (DRMAPI *GetErrorDescription)(DrmErrorCode_t nRetCode);
/* SDK init and deinit handling */

    class SDK
        {
      public:
	SDK() : fpInitialize(NULL), fpUninitialize(NULL)
	{
		GetFunction(g_hLib, "FC3Initialize", fpInitialize);
		GetFunction(g_hLib, "FC3Uninitialize", fpUninitialize);
		DrmErrorCode_t nRetCode = fpInitialize(NULL);
		if (nRetCode!=FPC_SUCCESS)
			throw Exception("Error (%d) while setting encoder callback: %s", (int)nRetCode, GetErrorDescription(nRetCode));
	}
	//SDK();
	virtual ~SDK()
	{
		DrmErrorCode_t nRetCode = fpUninitialize();
		if (nRetCode!=FPC_SUCCESS)
			throw Exception("Error (%d) while setting encoder callback: %s", (int)nRetCode, GetErrorDescription(nRetCode));
	}
public:
	DrmErrorCode_t (DRMAPI *fpInitialize)(const char* szReserved);
	DrmErrorCode_t (DRMAPI *fpUninitialize)(void);
};


现在我要在maincpp.cpp文件中调用FC3Initialize函数(如何?)


Now I want to call FC3Initialize function in my maincpp.cpp file(how ?)

推荐答案



这篇关于如何从另一个C ++文件中的C ++文件调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:13