简体   繁体   English

C++ 缺少类型说明符:语法错误

[英]C++ Missing type specifier: syntax error

I hook a function with windows detours in C++.我在 C++ 中将 function 与 windows 绕道挂钩。

I get an error in following code:我在以下代码中收到错误:

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

The compiler (MSVC++ 2008) says:编译器(MSVC++ 2008)说:

error C4430: Missing type specifier - int assumed.错误 C4430:缺少类型说明符 - 假定为 int。 Hint: "default-int" is not supported in C++.提示:C++ 不支持“default-int”。 Yadda yadda …亚达亚达…
error C2373: 'asmFunction': redefinition with different specifiers错误 C2373:“asmFunction”:使用不同的说明符重新定义
error C2440: 'in initialization': 'void (__cdecl *)(const char *)' cannot be converted to 'int'.错误 C2440:“初始化中”:“void (__cdecl *)(const char *)”无法转换为“int”。 There is no context in which this conversion is valid.没有此转换有效的上下文。

The code worked yesterday.该代码昨天工作。 What's wrong with it?它出什么问题了? How can I fix it without destructing the hook?如何在不破坏钩子的情况下修复它?

This expression needs to be within a function, eg此表达式需要在 function 内,例如

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

Go read a book on C++ . Go 阅读有关 C++ 的书

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C ++语法错误和缺少类型说明符 - C++ syntax error and missing type specifier C ++-错误C4430:缺少类型说明符(用于构造函数???) - C++ - Error C4430: missing type specifier (for a constructor???) 错误C4430:缺少类型说明符/错误C2143:语法错误:缺少';' 在“ *”之前 - error C4430: missing type specifier / error C2143: syntax error : missing ';' before '*' 缺少类型说明符 - 在C ++中假设为Int - Missing Type Specifier - Int Assumed in C++ C ++缺少类型说明符-是否假定为int? - C++ Missing type specifier - int assumed? C2143:语法错误:缺少';' '*'和C4430之前:缺少类型说明符-假定为int。 注意:C ++不支持default-int - C2143: syntax error: missing ';' before '*' & C4430: missing type specifier - int assumed. Note: C++ does not support default-int 错误C4430:缺少类型说明符 - error C4430 : missing type specifier 错误:缺少类型说明符 - Error: missing type specifier C ++:“错误C4430:缺少类型说明符 - 假设为int”对于构造函数和析构函数的无效声明 - C++: “error C4430: missing type specifier - int assumed” For constructor and invalid declaration for destructor shared-ptr 和错误 C4430:缺少类型说明符 - 假定为 int - C++ - shared-ptr and error C4430: missing type specifier - int assumed - C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM