D3D Menu problem!

Posts 1–2 of 2 · Page 1 of 1
D3D Menu problem!
Hello everybody!

I'm working with a D3D menu to display some things on the game screen, however, I am running into a very annoying bug! It is as follows:

error LNK2001: unresolved external symbol _D3DXCreateFontA@48
error LNK2001: unresolved external symbol _Direct3DCreate9@4


Therefore, I looked for various solutions on the internet, doing step by step every suggestion found by this huge world! But nothing worked, unfortunately.

Have followed all the tutorials found even in this forum, and also did not work ... It does no good to set the directories for Include/Lib or add references, also does not work. Have tried with SDK June 2010 and Summer 2004 no Lib/Include funcinou to compile too.

I used this code as scope, however, my code is now much more customized: http://pastebin.com/f6WKYDkW

Anyway, I was disabling function by function to find errors that prevent compilamento the source, and these two functions cause this error:

Code:
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <Mmsystem.h>
#include <time.h>
#include <stdio.h>
 
#include "CDetour/CDetour.h"
 
#pragma comment( lib, "winmm.lib" )
#pragma comment( lib, "d3d9.lib" )
#pragma comment( lib, "d3dx9.lib" )
 
CDetour d3dcreateDetour;
CDetour d3d9endsceneDetour;
CDetour d3d9resetDetour;
 
ID3DXFont *Fonte;
IDirect3DDevice9 *pInterface;
bool CriarComponentes = true;
bool b2 = false;
 
int __stdcall DllMain( HMODULE, DWORD, LPVOID );
void ApplyHooks( int );
 
void __stdcall myCreateDevice( IDirect3D9*, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS* , IDirect3DDevice9 ** );
void __stdcall myEndScene( IDirect3DDevice9* );
 
HRESULT __stdcall myReset( IDirect3DDevice9*, D3DPRESENT_PARAMETERS* );
 
void WriteTextOnScreen( int X, int Y, D3DCOLOR Cor, const char *Texto, ...)
{
    RECT Rect; Rect.bottom = Y + 1000; Rect.left = X; Rect.right = X + 1000; Rect.top = Y;
 
    char sTexto[256];
    va_list vArgumentList;
    va_start( vArgumentList, Texto);
    _vsnprintf_s( sTexto, sizeof( sTexto), sizeof( sTexto), Texto, vArgumentList );
    va_end( vArgumentList );
     
    //BORDER BLACK
    RECT Rect2 = { X + 1, Y + 1, X + 1, Y + 1 };    
    Fonte->DrawTextA( NULL, sTexto, -1, &Rect2, DT_NOCLIP, 0xFF000000 ); 
     
    Fonte->DrawTextA( NULL, sTexto, -1, &Rect, 0, Cor );
} 
 
void __stdcall myEndScene( IDirect3DDevice9 *UnidadeD3D9 )
{
    if( CriarComponentes )
    {
        D3DXCreateFontA( UnidadeD3D9, 16, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, 6, DEFAULT_PITCH | FF_DONTCARE, "Arial", &Fonte );
        CriarComponentes = false;
    }
 
    if( Fonte )
        WriteTextOnScreen( 10, 10, D3DCOLOR_ARGB( 255, 0, 255, 0 ), "Hello World from D3D9 !" );
}
 
HRESULT __stdcall myReset( IDirect3DDevice9 *UnidadeD3D9, D3DPRESENT_PARAMETERS* PresentationParameters )
{
    __asm pushad
 
    if( Fonte ){
        Fonte->OnLostDevice();
    }   
 
    HRESULT hRetn = (HRESULT)d3d9resetDetour.Org( UnidadeD3D9, PresentationParameters );
 
    if( SUCCEEDED( hRetn ) ){
        if(Fonte)
            Fonte->OnResetDevice();
    }
 
    __asm popad
 
    return hRetn;
}
 
void __stdcall myCreateDevice( IDirect3D9* d3d, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9 **ppReturnedDeviceInterface )
{
    d3dcreateDetour.Org( d3d, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface );
 
    pInterface = *ppReturnedDeviceInterface;
 
    if( !b2 )
        ApplyHooks( 2 );
}
 
void ApplyHooks( int nType )
{
    if( nType == 1 )
    {
        unsigned long* pD3DVTable;
 
        IDirect3D9* pD3D = Direct3DCreate9( D3D_SDK_VERSION );
         
        if( !pD3D ) // INVALID OBJECT
            return;
 
        pD3DVTable = (unsigned long*)*(unsigned long*)pD3D;
        pD3D->Release();
 
        // pD3DVTable[16] = IDirect3D9::CreateDevice
        d3dcreateDetour.Detour( (unsigned char*)pD3DVTable[16], (unsigned char*)myCreateDevice );
        d3dcreateDetour.Apply();
    }
    else if( nType == 2 )
    {
        unsigned long* pD3D9VTable;
 
        if( !pInterface )
            return;
 
        pD3D9VTable = (unsigned long*)*(unsigned long*)pInterface;
 
        // pD3D9VTable[42] = IDirect3DDevice9::EndScene
        d3d9endsceneDetour.Detour( (unsigned char*)pD3D9VTable[42], (unsigned char*)myEndScene, true );
        d3d9endsceneDetour.Apply();
 
        // pD3D9VTable[16] = IDirect3DDevice9::Reset
        d3d9resetDetour.Detour( (unsigned char*)pD3D9VTable[16], (unsigned char*)myReset );
        d3d9resetDetour.Apply();
 
        b2 = true;
    }
}
 
int __stdcall DllMain( HMODULE hModule, DWORD dwReason, LPVOID )
{
    DisableThreadLibraryCalls( hModule );
 
    if( dwReason == DLL_PROCESS_ATTACH )
    {
        ApplyHooks( 1 );
    }
 
    return true;
}[/php][/spoiler]

To desobrir where I was wrong, I was disabling function by function and compiling the source, until I found 2 functions that caused the errors mentioned above. Namely:

[php]
void __stdcall myEndScene( IDirect3DDevice9 *UnidadeD3D9 )
{
	if( CriarComponentes )
	{
		D3DXCreateFontA( UnidadeD3D9, 15, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, 6, DEFAULT_PITCH | FF_DONTCARE, "Arial", &Fonte );
		D3DXCreateFontA( UnidadeD3D9, 24, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, 6, DEFAULT_PITCH | FF_DONTCARE, "Verdana", &Event);
		D3DXCreateFontA( UnidadeD3D9, 40, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Impact", &m_lpFontACE );
		D3DXCreateFontA( UnidadeD3D9, 13, 0, FW_BOLD, 0, TRUE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, 6, DEFAULT_PITCH | FF_DONTCARE, "Arial", &Clock );
		D3DXCreateFontA( UnidadeD3D9, 16, 0, FW_BOLD, 0, TRUE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, 6, DEFAULT_PITCH | FF_DONTCARE, "Verdana", &Streak);
		
		CriarComponentes = false;
	}
And this:

Code:
void ApplyHooks( int nType ) // o erro tá nessa função \/ 
{
	if( nType == 1 )
	{
		unsigned long* pD3DVTable;
							
		IDirect3D9* pD3D = Direct3DCreate9( D3D_SDK_VERSION );
		
		if( !pD3D ) // INVALID OBJECT
			return;

		pD3DVTable = (unsigned long*)*(unsigned long*)pD3D;
		pD3D->Release();

		// pD3DVTable[16] = IDirect3D9::CreateDevice
		d3dcreateDetour.Detour( (unsigned char*)pD3DVTable[16], (unsigned char*)myCreateDevice );
		d3dcreateDetour.Apply();
	}
	else if( nType == 2 )
	{
		unsigned long* pD3D9VTable;

		if( !pInterface )
			return;

		pD3D9VTable = (unsigned long*)*(unsigned long*)pInterface;

		// pD3D9VTable[42] = IDirect3DDevice9::EndScene
		d3d9endsceneDetour.Detour( (unsigned char*)pD3D9VTable[42], (unsigned char*)myEndScene, true );
		d3d9endsceneDetour.Apply();

		// pD3D9VTable[16] = IDirect3DDevice9::Reset
		d3d9resetDetour.Detour( (unsigned char*)pD3D9VTable[16], (unsigned char*)myReset );
		d3d9resetDetour.Apply();

		isHook2Applied = true;
	} 
}
Please someone could help me solve this problem?
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us