Thread: MS Visual C++ Link Error with DirectX

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    3

    MS Visual C++ Link Error with DirectX

    I am trying to get a sample program running from a book caled "Tricks of Windows Game Programming. I have made a project of one of their samples and have set up my include and lib directories as best I could using the book and what I could find on the WEB. The final roblem I se ebefore I can actually start programmin gis the folllowing errors:


    Linking...
    demo6_3.obj : error LNK2001: unresolved external symbol _DirectDrawCreateEx@16
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/demo6_3.exe : fatal error LNK1120: 2 unresolved externals
    Error executing link.exe.

    I have double checked my Visuak C++ 6.0 settings and see nothing amiss. I downladed and installe dDirectX 9.0 into my C:\CXSDK directory as told to.

    Any ideas would be much appreciated

    Following is the start of code that I feel may apply.


    ------------------------------------------------------------------------------------

    // DEMO6_3.CPP basic full-screen pixel plotting DirectDraw demo

    // INCLUDES ///////////////////////////////////////////////

    #define WIN32_LEAN_AND_MEAN // just say no to MFC

    #define INITGUID // make sure directX guids are included

    #include <windows.h> // include important windows stuff
    #include <windowsx.h>
    #include <mmsystem.h>
    #include <iostream.h> // include important C/C++ stuff
    #include <conio.h>
    #include <stdlib.h>
    #include <malloc.h>
    #include <memory.h>
    #include <string.h>
    #include <stdarg.h>
    #include <stdio.h>
    #include <math.h>
    #include <io.h>
    #include <fcntl.h>

    #include <ddraw.h> // include directdraw

    // DEFINES ////////////////////////////////////////////////

    // defines for windows
    #define WINDOW_CLASS_NAME "WINCLASS1"

    // default screen size
    #define SCREEN_WIDTH 640 // size of screen
    #define SCREEN_HEIGHT 480
    #define SCREEN_BPP 8 // bits per pixel
    #define MAX_COLORS 256 // maximum colors

    // TYPES //////////////////////////////////////////////////////

    // basic unsigned types
    typedef unsigned short USHORT;
    typedef unsigned short WORD;
    typedef unsigned char UCHAR;
    typedef unsigned char BYTE;

    // MACROS /////////////////////////////////////////////////

    #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
    #define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

    // initializes a direct draw struct
    #define DD_INIT_STRUCT(ddstruct) { memset(&ddstruct,0,sizeof(ddstruct)); ddstruct.dwSize=sizeof(ddstruct); }

    // GLOBALS ////////////////////////////////////////////////
    HWND main_window_handle = NULL; // globally track main window
    HINSTANCE hinstance_app = NULL; // globally track hinstance

    // directdraw stuff

    LPDIRECTDRAW7 lpdd = NULL; // dd object
    LPDIRECTDRAWSURFACE7 lpddsprimary = NULL; // dd primary surface
    LPDIRECTDRAWSURFACE7 lpddsback = NULL; // dd back surface
    LPDIRECTDRAWPALETTE lpddpal = NULL; // a pointer to the created dd palette
    LPDIRECTDRAWCLIPPER lpddclipper = NULL; // dd clipper
    PALETTEENTRY palette[256]; // color palette
    PALETTEENTRY save_palette[256]; // used to save palettes
    DDSURFACEDESC2 ddsd; // a direct draw surface description struct
    DDBLTFX ddbltfx; // used to fill
    DDSCAPS2 ddscaps; // a direct draw surface capabilities struct
    HRESULT ddrval; // result back from dd calls
    DWORD start_clock_count = 0; // used for timing

  2. #2
    ok i dont know anything about what your trying to do
    but i think i recall there being a directx header file, maybe
    if you did #include <directx.h> in the #Include area, maybe
    the errors will go away, its worth a try, i guess lol.

    Good luck

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    It cant be an include problem since he is getting a link error.

    Make sure that you are linking to ddraw.lib

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    3
    Quote Originally Posted by bithub
    It cant be an include problem since he is getting a link error.

    Make sure that you are linking to ddraw.lib
    I am using MS Visual Studio's Visual C++ 6.0. As far as I can tell I am setup OK to link. I am going by the MS WEB site that tells how to set up to link to DirectX9 which I have installed. I have been all over the WEB and have had no luck getting anywhere.

    The code shown is the starting snippet from a game programming book, Its EXE file runs OK.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Check my response to your other question Maddog. I showed how to link to librarys there. Let me know if you have more trouble.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. Visual C++ 2005 linking and file sizes
    By Rune Hunter in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2005, 10:41 PM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  4. <list>
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 04:07 PM
  5. MS visual c++ 6 compiler problem
    By buck71 in forum C Programming
    Replies: 2
    Last Post: 10-30-2001, 04:09 AM