Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

So this is how my function actually looks like

DetourAttach(&(LPVOID&)lua_tolstring, (PBYTE)tostring);

lua_tolstring is const char* and LPVOID gives me this error.

typedef void* LPVOID
invalid type conversion

How can i make this work?

You don't have the right semantics for DetourAttach. The first argument is a pointer-to-pointer-to-function, which should be initialized to the original function being hooked. The second argument is a pointer-to-function containing your hook function.

See This blog for examples.

So you can't just pass the function. You have to initialize a variable, e.g.:

// Declaration of LUA API function in header
const char*lua_tostring (lua_State *L, int index);
// Your hook function must have this signature to match
const char*my_tostring (lua_State *L, int index);
// Your variable
const char* (*Real_lua_tostring)(lua_State *L, int index) = lua_tostring;
// Make the call
DetourAttach(&(LPVOID&)Real_lua_tolstring, (PVOID)my_tostring);
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.