Question

is there any way to call function from memory by address as prototype? This works really well on windows, but I don't know how to make it working on linux mainly because of __cdecl convention. Is there any way to do it on linux also? gcc always return this

error: function 'void MyFunction(int)' is initialized like a variable

Windows code:

void (WINAPIV *MyFunction)(int param) = (void (WINAPIV *)(int param))0x00000001;

void Print()
{
cout << "1" << endl;
}

#define __cdecl __attribute__((__cdecl__))

void (__cdecl *MyFunction)() = (void (__cdecl *)())&Print;

Sorry it's my mistake, it works thanks.

Était-ce utile?

La solution

How exactly are you trying to do it on Linux/GCC? This works for me (just removed the WINAPIV parts):

void (*MyFunction)(int param) = (void (*)(int param))0x00000001;

Anyway, BTW, many people say that having a typedef makes the syntax easier, i.e:

typedef void (*MyFunctionType)(int param);
MyFunctionType myFunction = (MyFunctionType)0x00000001;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top