I have the following code:
Header.hpp:
#ifndef HEADER_HPP_INCLUDED
#define HEADER_HPP_INCLUDED
#include<Windows.h>
extern HMODULE Module;
extern "C" bool __stdcall Initialized(void);
void (__stdcall *ptr_DetourPoint) (int X, int Y);
#endif //HEADER_HPP_INCLUDED
Header.cpp:
#include "Header.hpp"
HMODULE Module = nullptr;
bool __stdcall Initialize(void)
{
Module = LoadLibrary("Point.dll");
ptr_DetourPoint = reinterpret_cast<(__stdcall *)(int, int)>(GetProcAddress(Module, "PointFunc"));
return ptr_DetourPoint != nullptr;
}
extern "C" __stdcall HookDetourPoint(int X, int Y)
{
//Do stuff here..
ptr_DetourPoint(X, Y);
}
main.cpp:
#include <windows.h>
#include "Header.hpp"
extern "C" bool __stdcall DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
Initialized();
DisableThreadLibraryCalls(hinstDLL);
break;
case DLL_PROCESS_DETACH:
break;
default:
break;
}
return true;
}
In the above, when I compile it using Mingw 4.8, I get:
obj\Release\main.o:main.cpp:(.bss+0xb78): multiple definition of `ptr_DetourPoint'
obj\Release\Implementations\Header.o:Header.cpp:(.bss+0xb80): first defined here
Any ideas why I get that? I don't want to have to typedef my function pointer.