0

I hook a function with windows detours in C++.

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:

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.

The code worked yesterday. What's wrong with it? How can I fix it without destructing the hook?

drb
  • 728
  • 8
  • 21

1 Answers1

4

This expression needs to be within a function, e.g.

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

Go read a book on C++.

Community
  • 1
  • 1
Cat Plus Plus
  • 125,936
  • 27
  • 200
  • 224