【发布时间】:2016-12-10 15:36:36
【问题描述】:
我正在使用一些标准库为某些设备开发通用接口。 在代码的某些部分我有
//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);
我想知道:
-
TLopen()声明是什么?我替换了宏并得到了这个:
typedef int32_t( GC_CALLTYPE *PTLOpen )( TL_HANDLE *phTL );
但我对函数指针的学习方式不同,我希望是这样的:
typedef int32_t( *PTLOpen )( TL_HANDLE *phTL );
上面的声明还是一个函数指针吗? GC_CALLTYPE呢?
定义
FUNCTION_POINTER宏时function前面的#符号是什么?TLopen()函数的主体在哪里?我要包含一些.lib和.dll文件。正文可以以编译形式存在于这些文件中吗?
【问题讨论】:
标签: c++ function-pointers declaration calling-convention