尝试执行 DetourAttach 但无法将我的 lua 函数的数据类型转换为 LPVOID
Trying to do DetourAttach but cannot convert my lua function's datatype to LPVOID
这就是我的函数实际的样子
DetourAttach(&(LPVOID&)lua_tolstring, (PBYTE)tostring);
lua_tolstring
是 const char*
并且 LPVOID
给我这个错误。
typedef void* LPVOID
invalid type conversion
我怎样才能让它工作?
您没有正确的 DetourAttach 语义。第一个参数是一个指向函数指针的指针,它应该被初始化为被挂钩的原始函数。第二个参数是一个包含你的钩子函数的函数指针。
有关示例,请参阅 This blog。
所以你不能只传递函数。您必须初始化一个变量,例如:
// 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);
这就是我的函数实际的样子
DetourAttach(&(LPVOID&)lua_tolstring, (PBYTE)tostring);
lua_tolstring
是 const char*
并且 LPVOID
给我这个错误。
typedef void* LPVOID
invalid type conversion
我怎样才能让它工作?
您没有正确的 DetourAttach 语义。第一个参数是一个指向函数指针的指针,它应该被初始化为被挂钩的原始函数。第二个参数是一个包含你的钩子函数的函数指针。
有关示例,请参阅 This blog。
所以你不能只传递函数。您必须初始化一个变量,例如:
// 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);