Thread: DirectX Unresolved Externals

  1. #1
    Unregistered
    Guest

    DirectX Unresolved Externals

    Alright I am getting these errors
    directxplease.obj : error LNK2001: unresolved external symbol _DirectDrawCreateEx@16
    directxplease.obj : error LNK2001: unresolved external symbol _IID_IDirectDraw7
    Debug/directxone.exe : fatal error LNK1120: 2 unresolved externals

    with this code

    #include <windows.h>
    #include <ddraw.h>

    LPDIRECTDRAW7 g_DD = NULL;
    LPDIRECTDRAWSURFACE7 g_DDSPrimary = NULL;
    LPDIRECTDRAWSURFACE7 g_DDSBack = NULL;
    HWND g_hwnd;

    LRESULT CALLBACK WndProc(HWND hwnd,
    UINT Msg,
    WPARAM wParam,
    LPARAM lParam)

    {
    switch(Msg)
    {
    case WM_DESTROY :
    PostQuitMessage(0);
    return 0;
    case WM_SETCURSOR:
    SetCursor(NULL);
    return 0;
    }
    return DefWindowProc(hwnd, Msg, wParam, lParam);
    }


    static int InitApp(HINSTANCE hInstance, int nCmdShow)
    {
    WNDCLASS wc;
    DDSURFACEDESC2 sd;
    DDSCAPS ddsc;


    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hbrBackground =(HBRUSH) GetStockObject(BLACK_BRUSH);
    wc.hCursor =LoadCursor((HINSTANCE)NULL, IDC_ARROW);
    wc.hIcon =LoadIcon((HINSTANCE)NULL, IDI_APPLICATION);
    wc.hInstance =hInstance;
    wc.lpfnWndProc =WndProc;
    wc.lpszClassName ="MainWndClass";
    wc.lpszMenuName =NULL;

    if(!RegisterClass(&wc))
    {
    return FALSE;
    }

    g_hwnd = CreateWindow(wc.lpszClassName,
    "DirectDraw Sample 1",
    WS_POPUPWINDOW,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    (HWND) NULL,
    (HMENU) NULL,
    hInstance,
    (LPVOID) NULL);
    if(!g_hwnd)
    {
    return TRUE;
    }

    ShowWindow(g_hwnd,nCmdShow);
    UpdateWindow(g_hwnd);

    if FAILED(DirectDrawCreateEx(NULL,
    (void **)&g_DD,
    IID_IDirectDraw7,
    NULL))
    {
    return TRUE;
    }

    if FAILED(g_DD->SetCooperativeLevel(g_hwnd,
    DDSCL_EXCLUSIVE |
    DDSCL_FULLSCREEN))
    {
    return TRUE;
    }

    ZeroMemory(&sd, sizeof(sd));
    sd.dwSize =sizeof(sd);
    sd.dwFlags =DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
    sd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
    DDSCAPS_FLIP |
    DDSCAPS_COMPLEX;
    sd.dwBackBufferCount=1;

    if (FAILED(g_DD->CreateSurface(&sd,&g_DDSPrimary, NULL)))
    {
    return TRUE;
    }

    return TRUE;
    }


    int APIENTRY WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
    {
    MSG msg;
    InitApp(hInstance, nCmdShow);


    MessageBox(g_hwnd, "Press ALT+F4 TO QUIT....." , "MESSAGE", MB_OK);

    while(GetMessage(&msg, NULL, 0, 0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }

    return TRUE;
    }

    Thanks for any help

  2. #2
    Registered User The15th's Avatar
    Join Date
    Aug 2001
    Posts
    125
    maybe you should read the tutorial instead of just using the source code. im sure it will say link to whatever.lib...
    arrh, i got nothing good to say.
    http://www.praxis1.vic.edu.au/home/dcola/

  3. #3
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    you need to link the ddraw.lib to your project.
    if your include and lib paths are set right do try this at the top of your program
    #pragma comment(lib, "ddraw.lib")

  4. #4
    Unregistered
    Guest
    Funny you should say read the tutorial cause um I HAVE. I have setup the .lib and the include files under tools options in MSVC++ 4.0. But it still gives me erros.

    Ryan

  5. #5
    Registered User The15th's Avatar
    Join Date
    Aug 2001
    Posts
    125
    Hey ryan;
    sorry dude to jump to the conclusion that you haven't read the tut, its just that is a linker error, meaning you havent linked to the correct lib. Make sure you have DirectX SDK installed and setup correctly on your machine, and then add the .lib file. sorry i dont know which one it is, try adding them all and see if it compiles.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. unresolved externals??
    By pokiepo in forum C Programming
    Replies: 6
    Last Post: 07-02-2008, 11:38 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM