开发者

Linking against hard-coded function pointer

开发者 https://www.devze.com 2023-01-28 08:48 出处:网络
I know that a particular function with a known signatur开发者_开发知识库e is located at a known address. How do I initialise the function pointer in C++?

I know that a particular function with a known signatur开发者_开发知识库e is located at a known address. How do I initialise the function pointer in C++?

I have tried the following (and many variations thereof) to no avail:

int (*FunctionName)(int arg1, long arg2, char *arg3) = (int (*FunctionName)(int arg1, long arg2, char *arg3))0xCAKE;

I have a feeling it is the expression on the right hand side that is causing troubles, as the code will compile if it is initialised to 0x0 / NULL. Any pointers? (Pun intended).


Aside from the fact that CAKE is not a proper Hex value because K is not a valid hex character, plus any issues about different pointer types your main error is that FunctionName is a variable not a type.

It is like doing

px = (px)0xBADFACE;

where px is an regular pointer

If you remove FunctionName on the right leaving the rest it may work but easier would be a typedef.

typedef int( *FuncType)(int arg1, long arg2, char * arg3 );
FuncType FunctionName = (FuncType)(0xCAFE);


int (*FunctionName)(int arg1, long arg2, char *arg3) = (int ( * )(int arg1, long arg2, char *arg3))0x01;

Works in VS2008. FunctionName is the name of the variable and not part of the type.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号