Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //: This File On Paste Bin : https://pastebin.com/8CvECT98
- //:
- //: NOTE: theddmage says page 56 , 6.3.2.3 Pointers
- //: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf
- #include <windows.h>
- #include <stdint.h>
- #include <stdio.h>
- //: PROBLEM :
- //: You there is no gaurantee that casting
- //: a function to void* will give you the
- //: same address back when you cast the
- //: void* back to it's original type.
- //:
- //: I interpret this to mean "void*" is
- //: a "generic data pointer" because making
- //: it point to the address of a function is
- //: asking for trouble.
- //:
- //: SOLUTION :
- //:
- //: I think I am just trying to do something
- //: that can't be done. Function addresses
- //: cannot be implicitly casted to another
- //: function type.
- //:
- //: SEE: NOTICE_ME_SENPAI
- /** Okay, so it's not a "generic function pointer" **/
- /** type. There is no such thing. There is a **/
- /** generic data pointer ( void* ) , but no **/
- /** such equivalent with function pointers. **/
- /** **/
- /** You can cast between "void*" and back with **/
- /** data and be gauranteed to get the same address. **/
- /** **/
- /** You cannot cast between a function pointer **/
- /** and "void*" and be gauranteed to get the **/
- /** same address. **/
- typedef void ( defacto_generic_function )( void );
- /** Takes unspecified number of arguments, **/
- /** returns a signed 32 bit integer **/
- /** Your job to call it with correct # of args. **/
- /** Have I been writing too much JavaScript ? Maybe. **/
- typedef uint32_t ( f_i32 )( );
- defacto_generic_function* GETPROCADDRESS(
- void* dll_handle
- , const char* func_name
- ){
- defacto_generic_function* func_ptr =(
- (defacto_generic_function*)(
- GetProcAddress( dll_handle , func_name )
- ));;
- return( func_ptr );
- }
- int main( void ){
- void* dll_handle = LoadLibraryA( "gdi32.dll" );
- //: function pointers require cast ://
- defacto_generic_function* f_1 =(
- (defacto_generic_function*)
- (GetProcAddress( dll_handle , "ChoosePixelFormat" )) );
- f_i32* f_2 =(
- (f_i32*) //:<--- THIS CAST MUST BE HERE. < < < < < < < < < NOTICE_ME_SENPAI
- //: But, I wish I didn't have to have it here.
- (GETPROCADDRESS( dll_handle , "ChoosePixelFormat" )) );
- //: data pointer doesn't require a cast ://
- const char* look_mom_no_casting =malloc( 30 ); //: < < < < < NOTICE_ME_SENPAI
- if( f_1 ){ /** NOOP **/ };
- if( f_2 ){ /** NOOP **/ };
- if( look_mom_no_casting ){ /** NOOP **/ };
- printf( "[Hey_Hey_What_Do_You_Say?]\n" );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement