0

I want to use the repo detours.net in my project to hook native win32 api functions. It is working create for x64 applications but not for x86 applications. So I have changed to CMakeList.txt in the detours directory to -E env DETOURS_TARGET_PROCESSOR=X86 and creating the Visual Studio Project File with this command: cmake -G "Visual Studio 16 2019" -A Win32 ..\detours.net. After trying to build the solution i get an error in this line:

return DetourEnumerateImportsEx(hModule, &context, nullptr, Unsandbox);
Severity    Code    Description Project File    Line    Suppression State
Error   C2664   'BOOL DetourEnumerateImportsEx(HMODULE,PVOID,PF_DETOUR_IMPORT_FILE_CALLBACK,PF_DETOUR_IMPORT_FUNC_CALLBACK_EX)': cannot convert argument 4 from 'BOOL (__cdecl *)(PVOID,DWORD,LPCSTR,PVOID *)' to 'PF_DETOUR_IMPORT_FUNC_CALLBACK_EX'   DetoursDll  C:\Users\sebastian\source\repos\de32\detours.net\detours.net\DetoursDll\src\DetoursDll.cpp  30

But the definition of PF_DETOUR_IMPORT_FILE_CALLBACK to the function 'Unsandbox' seems correct:

typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK_EX)(_In_opt_ PVOID pContext,
                                                           _In_ DWORD nOrdinal,
                                                           _In_opt_ LPCSTR pszFunc,
                                                           _In_opt_ PVOID* ppvFunc);
static BOOL Unsandbox(_In_opt_ PVOID pContext, _In_ DWORD nOrdinal, _In_opt_ LPCSTR pszFunc, _In_opt_ PVOID* ppvFunc)

It's building without any problems for x64 but not for x86. Did I miss anything?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Sebi
  • 71
  • 1
  • 4
  • 2
    `CALLBACK` is probably the calling convention and is missing on the definition. It's probably a null macro in x64 but has a value in x86. – Richard Critten Mar 08 '21 at 13:14
  • Thanks for your response. I am new to c++ and only want to use the library in my .net project. Can you please explain a little bit more in detail? – Sebi Mar 08 '21 at 13:26
  • 2
    In your code change `static BOOL Unsandbox(...` to `static BOOL CALLBACK Unsandbox(...` Further reading https://learn.microsoft.com/en-us/cpp/cpp/calling-conventions?view=msvc-160 – Richard Critten Mar 08 '21 at 13:31

0 Answers0