我有以下代码:
头文件.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
头文件.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);
}
主.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;
}
在上面,当我使用 Mingw 4.8 编译它时,我得到:
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
任何想法为什么我得到那个?我不想键入我的函数指针。