C++ 缺少类型说明符 : syntax error

标签 c++ windows hook detours

我用 C++ 中的 windows 弯路 Hook 了一个函数。

我在以下代码中遇到错误:

void (*asmFunction)(const char *text);
void hookFunction(const char *text) {
    __asm nop;
    asmFunction(text);
}
asmFunction = (void (__cdecl *)(const char *))DetourFunction((PBYTE)0x433A90, (PBYTE)&hookFunction);

编译器 (MSVC++ 2008) 说:

error C4430: Missing type specifier - int assumed. Hint: "default-int" is not supported in C++. Yadda yadda …
error C2373: 'asmFunction': redefinition with different specifiers
error C2440: 'in initialization': 'void (__cdecl *)(const char *)' cannot be converted to 'int'. There is no context in which this conversion is valid.

代码昨天有效。它出什么问题了?如何在不破坏钩子(Hook)的情况下修复它?

最佳答案

这个表达式需要在一个函数中,例如

int main() {
    asmFunction = (void (__cdecl *)(const char *))DetourFunction(
        (PBYTE)0x433A90, (PBYTE)&hookFunction
    );
    // ...
}

去读a book on C++ .

关于C++ 缺少类型说明符 : syntax error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6641685/

相关文章:

c++ - 使用 SFINAE 检测成员函数

C++重载>>运算符奇怪的编译错误

windows - XAMPP Tomcat 不停止

python - 在 Windows 上构建 c 扩展的 Python 包

windows - Vagrant 未初始化常量 MixinSyncedFolders

git - Smartgit:自动插入提交消息

php - Woocommerce,删除产品页面上的价格

forms - 德鲁帕尔 6 : Hook for altering help field in a form

c++ - 实现 CRTP 链表混合 C++

c++ - Q_IMPORT_PLUGIN,我可以使用多少次?