Direct3D question

This is a discussion on Direct3D question within the Game Programming forums, part of the General Programming Boards category; For some reason, whenever I call Direct3DCreate9(D3D_SDK_VERSION) inside a class' member function such as: Code: HRESULT D3DControlObj::InitD3D(HWND hWnd) { if ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    44

    Direct3D question

    For some reason, whenever I call Direct3DCreate9(D3D_SDK_VERSION) inside a class' member function such as:
    Code:
    HRESULT D3DControlObj::InitD3D(HWND hWnd)
    {
        if ((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
        {
            return E_FAIL;
        }
    }
    I get the following linker error:

    D3D error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "public: long __thiscall D3DControlObj::InitD3D(struct HWND__ *)" (?InitD3D@D3DControlObj@@QAEJPAUHWND__@@@Z)

    but when I call it in a function in my main.cpp file it works fine.
    Code:
    HRESULT InitD3D(HWND hWnd)
    {
        if ((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
        {
            return E_FAIL;
        }
    }
    I really want to be able to use OOP and have a class that contains all of my Direct3D stuff usage. Any ideas on how to resolve this?
    Check out all my dimensions:
    Height, width, and for a limited time only... Depth!
    -sb

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Include the D3D headers in the file with your class.

    Oh, and if it's a seperate project, make sure you're linking the right libraries in the project with the classes.
    Away.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    5
    The way I keep make sure all my source has the right include files is just make a header file like common.h Something like this:

    Code:
    // common.h - common include files
    #ifndef _COMMON_H_
    #define _COMMON_H_
    
    #include <d3d.h>
    #include <dsound.h>
    #include <whateverneedsincluding.h>
    //....
    
    #endif
    Then in all of the source files of your project make sure to put #include "common.h" in it.

    This should solve most problems. Of course you will want to make sure that you have the libraries defined.

    If you are using VC++ just go to Project->Settings: Link Tab: library modules and add the libraries there. or if you like everything in code, put this in one of your source files (preferably the main one):

    Code:
    #pragma comment(lib, d3d.lib)
    #pragma comment(lib, etcblahblah.lib)
    hope this helps.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    44
    Right. I do the same.

    My main.h file (included in every file in my project):
    Code:
    #ifndef main_h
    #define main_h
    
    #include <d3d9.h>
    #other includes
    
    #endif
    That doesn't seem to be the problem.
    Check out all my dimensions:
    Height, width, and for a limited time only... Depth!
    -sb

  5. #5
    Registered User
    Join Date
    Feb 2005
    Posts
    1
    Here's my include statements and what not in my gameEngine.h file. I just put all my include statements in this file, makes it a lot easier.

    #ifndef _GAMEENGINE_H_
    #define _GAMEENGINE_H_

    #include <windows.h>
    // DirectX Includes for Direct3D
    #include <d3d9.h>
    #pragma comment(lib, "d3d9.lib") // Direct3D would NOT work until I put this in.
    // Although I compiled the examples and there was no problem... no idea why.


    If that #pragma doesn't work, check out :
    http://msdn.microsoft.com/library/de...ir_comment.asp
    for more information... hope it helps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why use Direct3D?
    By m3rk in forum Tech Board
    Replies: 42
    Last Post: 05-22-2009, 09:08 AM
  2. Need help with getting DirectX 9.0 initilization
    By DarkMortar in forum Windows Programming
    Replies: 7
    Last Post: 05-09-2006, 08:58 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21