I’m using Visual Studion 2010, and given the following example function obtained from WinGDI.h:
__gdi_entry WINGDIAPI int WINAPI AbortDoc(__in HDC hdc);
Is there a way to declare a function pointer of this type, or maybe put it into a typedef. For example:
AbortDoc() MyAbortDocPtr;
typedef AbortDoc AbortDocType;
Obviously these are not syntactically correct, and won’t compile, and maybe want I want to do cant’ be done at all. However, there is a solution in which you can hand jam every typedef yourself as follows:
typedef int (WINAPI *AbortDocType)( HDC hdc );
I’ve used this, and it does work for me, but….
- Its tedious, especially if you are doing it for 100 routines.
- Because its tedious its error prone, and you might get a signature wrong and not know it until a fringe case executes the bugged code.
- Should the base signatures change in the header file you are responsible for finding out which ones changed and correcting them. This means hand inspection of all the routines vs just grabbing the new header file and recompiling.
Anyone know how I can use pre-defined function declarations in typdefs, or simply use the original declaration as a typedef to declare a new function pointer?
You can use
decltypeto deduce the type of the function pointer.Output: