GetProcAddress returns a function pointer. Lets suppose we get the address of the function Beep ( its declaration can be found at WinBase.h (when including Windows.h))
BOOL WINAPI Beep(
_In_ DWORD dwFreq,
_In_ DWORD dwDuration
);
then the classic code could look something like
typedef BOOL(__stdcall *pbeep)(DWORD , DWORD );
pbeep beep = NULL;
FARPROC fptr = GetProcAddress(Hnd,"Beep");
beep = reinterpret_cast<pbeep>(fptr);
if( beep != NULL ) {
beep( 440, 1200 ); //this generates a beep for 1.2 secs...
}
Everything looks good and works. My question:
Is there any way I can avoid the typedef declaration considering the compiler could "somehow" get the function pointer "information" from the already included Beep() declaration from WinBase.h. My goal is to somehow re-use the info (return/parameters/etc) already contained at the already included .h file where the Beep() function is declared w/o having to manually repeat all of that info on a typedef. when doing it for one function it's ok but when the number of functions grows those typedef are really a pain and a big source of errors. Can that be done?
edit; I'm moving to VS 2013 soon but so far still using VS2008 then the idea is doing this w/o C++11