我希望能够在类中包含我的typedef函数.但我找不到办法做到这一点.我需要扫描地址,所以我不能硬编码,因此我需要像这个SetCursorPosFunction =(_ SetCursorPos)(地址到函数)设置地址; 例: class
例:
class Cursor { public: typedef BOOL(__stdcall *_SetCursorPos) (int X, int Y); _SetCursorPos SetCursorPosFunction; };
我想能够像这样调用Cursor :: SetCursorPosFunction(x,y)这个函数
我的意思的例子.
void Function() { DWORD_PTR AddressToFunctionSetCourserPos = Find(....); Cursor::SetCursorPosFunction = (Cursor::_SetCursorPos)(AddressToFunctionSetCourserPos ); //In final version it is going to be in a separate function where i get all the functions i need (This find() function can not be looped or called often, it is going to create lag etc.). Cursor::SetCursorPosFunction(1, 1); }
我得到错误:
fatal error LNK1120: 1 unresolved externals error LNK2001: unresolved external symbol "public: static int (__cdecl* Cursor::SetCursorPosFunction)(int,int)" (?SetCursorPosFunction@Cursor@@2P6AHHH@ZEA)将函数修改为静态将允许您使用它而无需首先实例化成员,如下所示:
class Cursor { public: typedef BOOL(__stdcall *_SetCursorPos) (int X, int Y); static _SetCursorPos SetCursorPosFunction; };
Cursor :: SetCursorPosFunction(x,y)现在应该可以工作(先给它初始化).
您还需要在全局空间中初始化静态成员.像Cursor :: _ SetCursorPos Cursor :: SetCursorPosFunction = nullptr;应该管用.但要注意只在一个翻译单元中使用它.