C ++中的接口 - 头文件

时间:2017-06-17 12:59:18

标签: c++ interface com header-files idl

我应该写一个与uEye相机交互的C ++程序。 为此我必须包含几个文件,其中一个是头文件,其中有大约30个接口,如下所示。 当我运行包含此头文件的c ++程序时,我得到错误:

"错误:预期的标识符或'('之前':'令牌"

在头文件中每个接口的第一行(接口IuEyeAutoFeatures:public IUnknown)。

继承头文件中的一个接口:

interface IuEyeAutoFeatures : public IUnknown
{
    STDMETHOD(SetAutoBrightnessReference)(long lReference) = 0;
    STDMETHOD(GetAutoBrightnessReference)(long* plReference) = 0;
    STDMETHOD(SetAutoBrightnessMaxExposure)(long lMaxExposure) = 0;
    STDMETHOD(GetAutoBrightnessMaxExposure)(long* plMaxExposure) = 0;
    STDMETHOD(SetAutoBrightnessMaxGain)(long lMaxGain) = 0;
    STDMETHOD(GetAutoBrightnessMaxGain)(long* plMaxGain) = 0;
    STDMETHOD(SetAutoBrightnessSpeed)(long lSpeed) = 0;
    STDMETHOD(GetAutoBrightnessSpeed)(long* plSpeed) = 0;
    STDMETHOD(SetAutoBrightnessAOI)(long lXPos, long lYPos, long lWidth, long lHeight) = 0;
    STDMETHOD(GetAutoBrightnessAOI)(long* plXPos, long* plYPos, long* plWidth, long* plHeight) = 0;
    STDMETHOD(SetAutoWBGainOffsets)(long lRedOffset, long lBlueOffset) = 0;
    STDMETHOD(GetAutoWBGainOffsets)(long* plRedOffset, long* plBlueOffset) = 0;
    STDMETHOD(SetAutoWBGainRange)(long lMinRGBGain, long lMaxRGBGain) = 0;
    STDMETHOD(GetAutoWBGainRange)(long* plMinRGBGain, long* plMaxRGBGain) = 0;
    STDMETHOD(SetAutoWBSpeed)(long lSpeed) = 0;
    STDMETHOD(GetAutoWBSpeed)(long* plSpeed) = 0;
    STDMETHOD(SetAutoWBAOI)(long lXPos, long lYPos, long lWidth, long lHeight) = 0;
    STDMETHOD(GetAutoWBAOI)(long* plXPos, long* plYPos, long* plWidth, long* plHeight) = 0;
};
DEFINE_GUID(IID_IuEyeFaceDetection, 
            0xe122a994, 0xfc4d, 0x445b, 0xb2, 0x1c, 0x30, 0x8b, 0x67, 0x48, 0x44, 0xe0);

#ifndef DS_EXPORT
#   define DS_EXPORT
#   ifdef _UEYETIME
#       undef _UEYETIME
#   endif
#   ifdef UEYETIME
#       undef UEYETIME
#   endif
typedef struct _UEYETIME
{
    WORD      wYear;
    WORD      wMonth;
    WORD      wDay;
    WORD      wHour;
    WORD      wMinute;
    WORD      wSecond;
    WORD      wMilliseconds;
    BYTE      byReserved[10];
} UEYETIME;
#endif  /* DS_EXPORT */

#ifndef DS_EXPORT
#   define DS_EXPORT
#   ifdef S_FDT_INFO_EL
#       undef S_FDT_INFO_EL
#   endif
#   ifdef FDT_INFO_EL
#       undef FDT_INFO_EL
#   endif
/*!
 * \brief uEye face detection info element data type.
 * Info on a single detected face as listed by \see FDT_INFO_LIST.
 */
typedef struct S_FDT_INFO_EL
{
    INT nFacePosX;              /*!< \brief Start X position.                                                               */
    INT nFacePosY;              /*!< \brief Start Y position.                                                               */
    INT nFaceWidth;             /*!< \brief Face width.                                                                     */
    INT nFaceHeight;            /*!< \brief Face height.                                                                    */
    INT nAngle;                 /*!< \brief Face Angle (0...360° clockwise, 0° at twelve o'clock position. -1: undefined ).  */
    UINT nPosture;              /*!< \brief Face posture.                                                                   */
    UEYETIME TimestampSystem;   /*!< \brief System time stamp (device query time) .                                         */
    UINT64 nReserved;           /*!< \brief Reserved for future use.                                                        */
    UINT nReserved2[4];         /*!< \brief Reserved for future use.                                                        */
} FDT_INFO_EL;
#endif  /* DS_EXPORT */

#ifndef DS_EXPORT
#   define DS_EXPORT
#   ifdef S_FDT_INFO_LIST
#       undef S_FDT_INFO_LIST
#   endif
#   ifdef FDT_INFO_LIST
#       undef FDT_INFO_LIST
#   endif
/*!
 * \brief uEye face detection info list data type.
 * List of detected faces, lists \see FDT_INFO_EL objects.
 */
typedef struct S_FDT_INFO_LIST
{
    UINT nSizeOfListEntry;      /*!< \brief Size of one list entry in byte(in).     */
    UINT nNumDetectedFaces;     /*!< \brief Number of detected faces(out).          */
    UINT nNumListElements;      /*!< \brief Number of list elements(in).            */ 
    UINT nReserved[4];          /*!< \brief reserved for future use(out).           */ 
    FDT_INFO_EL FaceEntry[1];   /*!< \brief First face entry.                           */
} FDT_INFO_LIST;
#endif  /* DS_EXPORT */

据我所知,使用&#34; interface&#34;这个词来声明接口。是用Java等语言完成的,但不是用c ++编写的,所以我不明白为什么这个头文件声明这样的接口。由于这个头文件是由公司IDS在下载驱动程序后提供的,所以我认为应该是正确的。

如何修复该错误并使我的程序正常运行?

提前致谢

1 个答案:

答案 0 :(得分:1)

interface是预处理器宏,通常与COM接口一起使用。它在 combaseapi.h 中定义为:

#define __STRUCT__ struct
#define interface __STRUCT__

在包含接口标头之前,您需要包含该头文件(直接或间接通过#include <objbase.h>)。