Search code examples
c++64-bitdirectx

C++ DirectX 9 unresolved external symbol


Yes I included all the libs but every time I run my program in x64 it gives me an unresolved symbol but works perfectly in x32??

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol Direct3DCreate9Ex referenced in function "int cdecl DirectXInit(struct HWND *)" (?DirectXInit@@YAHPEAUHWND__@@@Z) DirectX Overlay D:\VSprojects\2020\Mygui\Garrysmod take 2\Overlay aimbot\DirectX.obj 1

Source

    int DirectXInit(HWND hWnd)
    {
        if (FAILED(Direct3DCreate9Ex(D3D_SDK_VERSION, &p_Object)))
            exit(1);

        ZeroMemory(&p_Params, sizeof(p_Params));
        p_Params.Windowed = TRUE;
        p_Params.SwapEffect = D3DSWAPEFFECT_DISCARD;
        p_Params.hDeviceWindow = hWnd;
        p_Params.MultiSampleQuality = D3DMULTISAMPLE_NONE;
        p_Params.BackBufferFormat = D3DFMT_A8R8G8B8;
        p_Params.BackBufferWidth = Width;
        p_Params.BackBufferHeight = Height;
        p_Params.EnableAutoDepthStencil = TRUE;
        p_Params.AutoDepthStencilFormat = D3DFMT_D16;

        if (FAILED(p_Object->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &p_Params, 0, &p_Device)))
            exit(1);

        return 0;
    }





    char playerO[350] = { 0 };
    char enemyO[300] = { 0 };
    char aimbotO[300] = { 0 };
    char rect[300] = { 0 };
    int counter = 15;

    int Render()
    {


            p_Device->Clear(0, 0, D3DCLEAR_TARGET, 0, 1.0f, 0);
            p_Device->BeginScene();


            //Drawing Stuff

            DrawBorderBox(10, 10, 200, 200, 15, 255, 255, 0, 0);


            p_Device->EndScene();
            p_Device->PresentEx(0, 0, 0, 0, 0);
            return 0;

    }

Header

 #ifndef DIRECTX_H
#define DIRECTX_H


#include "Main.h"
#include "Drawings.h"
#include "read.h"

#include <Windows.h>
#include <iostream>


#include <d3d9.h>
#include <d3dx9.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")


#include <dwmapi.h>
#pragma comment(lib, "dwmapi.lib")


extern IDirect3D9Ex* p_Object;
extern IDirect3DDevice9Ex* p_Device;
extern D3DPRESENT_PARAMETERS p_Params;
extern ID3DXLine* p_Line;
extern ID3DXFont* pFontSmall;

extern RECT rc;

int DirectXInit(HWND hWnd);
int Render();

#endif

Again, it is most likely not do to with an include because it works like a clock in x32.


Solution

  • With the legacy DirectX SDK, you have to set up distinct x86 vs. x64 library include paths:

    In VC++ Directories for 32-bit configurations:

    $(IncludePath);$(DXSDK_DIR)Include
    $(LibraryPath);$(DXSDK_DIR)Lib\x86
    

    In VC++ Directories for 64-bit configurations:

    $(IncludePath);$(DXSDK_DIR)Include
    $(LibraryPath);$(DXSDK_DIR)Lib\x64
    

    See Microsoft Docs

    For new projects you should be using Direct3D 11, and you do not need to use the legacy DirectX SDK at all.