プロキシ dll を書き込もうとしているようです。組み立ての必要はありません。
まず、これを読むことをお勧めします。
次に、Microsoft リンカにはプラグマがあり、関数名を指定してエクスポートし、関数を別の dll に転送できます。
プラグマは次のようになります。
#pragma comment(linker, "/export:SwapBuffers=gdi32.SwapBuffers") //this will forward call from your dll into original dll you're "overriding".
#pragma comment(linker, "/export:TextOutA=_HookedTextOutA@20") //and this will let you use your own function
プロキシ dll コードは次のようになります。
#include <windows.h>
#include <gdi32_fwd.h>
#pragma pack(1)
#include <stdio.h>
#include <stdarg.h>
static HINSTANCE hLThis = 0;
static HINSTANCE hGDI32 = 0;
static TCHAR prtBuf[0x1000];
static BOOL (WINAPI* Gdi32_TextOutA)(
__in HDC hdc,
__in int nXStart,
__in int nYStart,
__in LPSTR lpString,
__in int cbString
);
static HFONT (WINAPI* Gdi32_CreateFontIndirectA)(
const LOGFONTA* lplf
);
extern "C" HFONT WINAPI HookedCreateFontIndirectA(
const LOGFONTA* lplf
){
LOGFONTA lf;
//override data here
...
return Gdi32_CreateFontIndirectA(lplf);
}
extern "C" BOOL WINAPI HookedTextOutA(
__in HDC hdc,
__in int nXStart,
__in int nYStart,
__in LPSTR lpString,
__in int cbString
){
//override data here
....
return Gdi32_TextOutA(hdc, nXStart, nYStart, lpString, cbString);
}
//! Attach or detach this proxy.
BOOL WINAPI DllMain( HINSTANCE hInst,DWORD reason,LPVOID )
{
if( reason == DLL_PROCESS_ATTACH )
{
hLThis = hInst;
hGDI32 = LoadLibrary( "gdi32" );
if( !hGDI32 )
{
return FALSE;
}
*(void **)&Gdi32_TextOutA = (void *)GetProcAddress( hGDI32, "TextOutA");
*(void **)&Gdi32_CreateFontIndirectA = (void *)GetProcAddress( hGDI32, "CreateFontIndirectA");
}
else if( reason == DLL_PROCESS_DETACH )
{
FreeLibrary( hGDI32 );
}
return TRUE;
}
//! End of file.
ヘッダ:
#pragma comment(linker, "/export:AbortDoc=gdi32.AbortDoc")
#pragma comment(linker, "/export:AbortPath=gdi32.AbortPath")
#pragma comment(linker, "/export:AddFontMemResourceEx=gdi32.AddFontMemResourceEx")
#pragma comment(linker, "/export:AddFontResourceA=gdi32.AddFontResourceA")
#pragma comment(linker, "/export:AddFontResourceExA=gdi32.AddFontResourceExA")
#pragma comment(linker, "/export:AddFontResourceExW=gdi32.AddFontResourceExW")
#pragma comment(linker, "/export:AddFontResourceTracking=gdi32.AddFontResourceTracking")
#pragma comment(linker, "/export:AddFontResourceW=gdi32.AddFontResourceW")
#pragma comment(linker, "/export:AngleArc=gdi32.AngleArc")
#pragma comment(linker, "/export:AnimatePalette=gdi32.AnimatePalette")
#pragma comment(linker, "/export:AnyLinkedFonts=gdi32.AnyLinkedFonts")
#pragma comment(linker, "/export:Arc=gdi32.Arc")
#pragma comment(linker, "/export:ArcTo=gdi32.ArcTo")
#pragma comment(linker, "/export:BRUSHOBJ_hGetColorTransform=gdi32.BRUSHOBJ_hGetColorTransform")
#pragma comment(linker, "/export:CreateEnhMetaFileA=gdi32.CreateEnhMetaFileA")
#pragma comment(linker, "/export:CreateEnhMetaFileW=gdi32.CreateEnhMetaFileW")
#pragma comment(linker, "/export:CreateFontA=gdi32.CreateFontA")
//#pragma comment(linker, "/export:CreateFontIndirectA=gdi32.CreateFontIndirectA")
#pragma comment(linker, "/export:CreateFontIndirectA=_HookedCreateFontIndirectA@4")
...
#pragma comment(linker, "/export:CreateFontIndirectExA=gdi32.CreateFontIndirectExA")
#pragma comment(linker, "/export:CreateFontIndirectExW=gdi32.CreateFontIndirectExW")
#pragma comment(linker, "/export:CreateFontIndirectW=gdi32.CreateFontIndirectW")
#pragma comment(linker, "/export:SwapBuffers=gdi32.SwapBuffers")
//#pragma comment(linker, "/export:TextOutA=gdi32.TextOutA")
#pragma comment(linker, "/export:TextOutA=_HookedTextOutA@20")
...
#pragma comment(linker, "/export:bInitSystemAndFontsDirectoriesW=gdi32.bInitSystemAndFontsDirectoriesW")
#pragma comment(linker, "/export:bMakePathNameW=gdi32.bMakePathNameW")
#pragma comment(linker, "/export:cGetTTFFromFOT=gdi32.cGetTTFFromFOT")
#pragma comment(linker, "/export:gdiPlaySpoolStream=gdi32.gdiPlaySpoolStream")