[MS Detours] Passing function as parameter, Identified undefined

Hi, I am trying to hook a function with Detours 3 and have the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include <Windows.h>
#include "detours.h"

#pragma comment(lib, "detours.lib")

static int (WINAPI* TrueMessageBoxA)(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType) = MessageBoxA;

int __stdcall FuncHookMessageboxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)
{
	MessageBoxA(0, lpText, lpCaption, 0);
	return MessageBoxA(hWnd, lpText, lpCaption, uType);
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{	
	switch (ul_reason_for_call)
	{

	case DLL_PROCESS_ATTACH:
		DisableThreadLibraryCalls(hModule);
		DetourRestoreAfterWith();
		
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		DetourAttach(&(PVOID&)TrueMessageBoxA, FuncHookMessageBoxA);
		DetourTransactionCommit();
		break;
	case DLL_PROCESS_DETACH:
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		DetourDetach(&(PVOID&)TrueMessageBoxA, FuncHookMessageBoxA);
		DetourTransactionCommit();
		break;
	}
	return TRUE;
}


For comparison, here is the example code on Microsoft's wiki https://github.com/microsoft/detours/wiki/Using-Detours

So I am following the example yet at line 30 @ "FuncHookMessageBoxA" I have the error: "identifier is undefined" although I do have the function defined right above DllMain.

I am using VS2017 and have tried 2008 and I don't see the error at first glance so could someone please point out my error?
Last edited on
You've defined a function named FuncHookMessageboxA, you are trying to pass a function named FuncHookMessageBoxA.

Please learn to use code tags, they make reading and commenting on source code MUCH easier.

How to use code tags: http://www.cplusplus.com/articles/jEywvCM9/

There are other tags available.

How to use tags: http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either
How I missed that, silly of me. I guess I was distracted.

I added that tags.
I am using VS2017

There are newer versions of Visual Studio available, both have free editions. VS 2019 & VS 2022 Community.

You should consider upgrading to VS 2019.
https://docs.microsoft.com/en-us/visualstudio/releases/2019/system-requirements

If you are on Win10 (or Win11) and have an x64 processor VS 2022 would be a good choice.
https://docs.microsoft.com/en-us/visualstudio/releases/2022/system-requirements

I used VS 2017 -- started with VS 2015 (I like free) -- and gladly upgraded to VS 2019 when it was released, and then VS 2022. Each new version was better than the last.

VS 2017 is out-dated, including the ability to create WinAPI apps. 2019 & 2022 are currently the only compilers that are fully C++20 compliant if that matters to ya. 2019 & 2022 can use newer C language standards, C11 & C17.

You can install 2019 and/or 2022 "in parallel" with 2017 if you want, I currently have 2019 & 2022 installed together.

I liked VS 2017, but I don't regret doing the upgrades. 2019 and especially 2022 IMO just work better.
Topic archived. No new replies allowed.