c++ - 类中的 Typedef 函数

标签 c++ function class typedef stdcall

我希望能够在类中使用我的 typedef 函数。但我找不到办法做到这一点。我需要扫描地址,所以我不能硬编码,因此我需要像这样设置地址 SetCursorPosFunction = (_SetCursorPos)(address to function);

例子:

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)

最佳答案

将函数修改为static 将允许您使用它而不必根据需要先实例化一个成员:

class Cursor
{
public:
    typedef BOOL(__stdcall *_SetCursorPos) (int X, int Y);
    static _SetCursorPos SetCursorPosFunction;
};

Cursor::SetCursorPosFunction(x,y) 现在应该可以工作(前提是您首先对其进行了初始化)。

您还需要在全局空间中初始化静态成员。像 Cursor::_SetCursorPos Cursor::SetCursorPosFunction = nullptr; 这样的东西应该可以工作。但要注意只在一个翻译单元中使用它。

关于c++ - 类中的 Typedef 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51899619/

相关文章:

c++ - libcurl下载速度太慢

javascript - 如何创建折扣计算功能?

swift - 如何访问枚举之外的属性

c++ - 像 ArrayFire 中的 Numpy 一样分散/聚集

c# - Windows Mobile 中的 openCV

c++ - std::function 无法区分重载函数

javascript - 使用 onsubmit 在 JS 中提交表单

javascript - 在其他列表的基础上填充列表

ruby-on-rails - 在模型中使用辅助方法

c++ - 没有匹配的调用函数,但从未调用过那个确切的函数