这是否仍然为一种指针函数声明了一个别名?

时间:2016-12-10 15:36:37

标签: c++ function-pointers declaration calling-convention

我正在使用一些标准库来开发某些设备的通用接口。 在代码的某些部分我有

//header.h

#ifndef _M_X64
#  define GC_CALLTYPE __stdcall
#else
#  define GC_CALLTYPE /* default */  //this is my case
#endif

...


typedef int32_t GC_ERROR;

...


/* typedefs for dynamic loading */

#define GC_API_P(function) typedef GC_ERROR( GC_CALLTYPE *function )
GC_API_P(PTLOpen)( TL_HANDLE *phTL );

在我的源文件中

//source1.cpp

TLOpen(&hTl)

//source2.cpp

#define FUNCTION_POINTER(function, ptype, hModule) \
   ((function) = reinterpret_cast<ptype>(GetProcAddress((hModule), #function)))  // What is this #?
GC::PTLOpen TLOpen = 0;
FUNCTION_POINTER(TLOpen, GC::PTLOpen, hModule);

我想找出:

  1. 什么是TLopen()声明?我替换了宏并得到了这个:
  2. typedef int32_t( GC_CALLTYPE *PTLOpen )( TL_HANDLE *phTL );

    但我学习了不同的函数指针,我期待这样的事情:

    typedef int32_t( *PTLOpen )( TL_HANDLE *phTL );

    上面的声明仍然是一个函数指针吗?那么GC_CALLTYPE呢?

    1. 在定义#宏之前,function之前的FUNCTION_POINTER符号是什么?

    2. TLopen()的身体在哪里?我要包含一些.lib.dll个文件。是否可以以编译形式存在于这些文件中?

1 个答案:

答案 0 :(得分:1)

  1. __stdcall位于Joe Duffy说明符所在的位置(如GC_CALLTYPE)。 可以因为不要忘记非常容易#function也可以扩展为空字符串。快速搜索提出了一个问题,其中此语法在SO中进行了讨论:calling convention

  2. 这称为字符串化:例如,如果相应的宏参数为"xyz"xyz将扩展为{{1}}。更多How to declare an __stdcall function pointer

  3. 是的,它可以,实际上。您的API将告诉您如何进行编译,以便程序可以找到该功能。这是拥有库和here

  4. 的全部目的