Thread: Problems with my DirectX program

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    62

    Problems with my DirectX program

    My DirectX program doesn't work. It gives me no errors, but if I run it, it gives me errors. What's wrong with it?

    I do not write my mywin.h and basic.h here, because they are not important and work correctly. Procedures from those header files are Logi, MkWin and ReggWin and TPump, so do not be confused of them, just ignore them.

    My code is here:

    main.cpp:


    Code:
    #define WIN32_LEAN_AND_MEAN
    
    
    
    #include <D3d9.h> 
    
    #include "mywin.h"
    
    #include "basic.h"
    
    
    
    #pragma comment(lib,"User32.lib") 
    
    #pragma comment(lib, "d3d9.lib") 
    
     
    
    
    
    WNDPROC wndProc; 
    
    HINSTANCE hInstance; 
    
    HWND _hwnd;
    
    HRESULT hr;
    
    
    
    IDirect3D9 *g_D3D=NULL;
    
    D3DFORMAT format=D3DFMT_R5G6B5;
    
    D3DPRESENT_PARAMETERS pp;
    
    IDirect3DDevice9 *p_device=NULL;
    
     
    
    char logi_name []= "error.txt";
    
    char className [] = "WinClass";
    
    char const caption [] = "Window";
    
    int width=500;
    
    int height=500;
    
    int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow)
    
    {
    
    wndProc=WindowProcedure;
    
    //Registrating window class.
    
    hr=ReggWin (wndProc, className, hInst);
    
    if(FAILED(hr)){
    
    Logi("Error, can't regg window class.",logi_name);
    
    }
    
    //Making Window.
    
    hr=MkWin (caption, className, hInst, _hwnd, cmdShow, width, height);
    
    if(FAILED(hr)){
    
    Logi("Error, can't create window.",logi_name);
    
    }
    
    //Creating DirectX object
    
    g_D3D = Direct3DCreate9( D3D_SDK_VERSION);
    
    if(!g_D3D){
    
    Logi("Error, can't create DirectX device.", logi_name);
    
    }
    
     
    
    ZeroMemory(&pp,sizeof(D3DPRESENT_PARAMETERS));
    
    pp.BackBufferCount= 1; //We only need a single back buffer
    
    pp.MultiSampleType=D3DMULTISAMPLE_NONE; //No multi-sampling
    
    pp.MultiSampleQuality=0; //No multi-sampling
    
    pp.SwapEffect = D3DSWAPEFFECT_DISCARD; // Throw away previous frames, we don't need them
    
    pp.hDeviceWindow=_hwnd; //This is our main (and only) window
    
    pp.Flags=0; //No flags to set
    
    pp.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT; //Default Refresh Rate
    
    pp.PresentationInterval=D3DPRESENT_INTERVAL_DEFAULT; //Default Presentation rate
    
    pp.BackBufferFormat=format; //Display format
    
    pp.EnableAutoDepthStencil=FALSE; //No depth/stencil buffer
    
    pp.Windowed = TRUE;
    
     
    
    hr=g_D3D->CreateDevice(D3DADAPTER_DEFAULT, //The default adapter, on a multi-monitor system
    
    //there can be more than one.
    
    D3DDEVTYPE_HAL, //Use hardware acceleration rather than the software renderer
    
    //Our Window
    
    _hwnd,
    
    //Process vertices in software. This is slower than in hardware,
    
    //But will work on all graphics cards.
    
    D3DCREATE_SOFTWARE_VERTEXPROCESSING,
    
    //Our D3DPRESENT_PARAMETERS structure, so it knows what we want to build
    
    &pp,
    
    //This will be set to point to the new device
    
    &p_device); 
    
    if(FAILED(hr)){
    
    Logi("Error, can't create DirectX device.", logi_name);     //I get this error message!
    
    }
    
    //Message pump
    
    TPump();
    
    //Destroying DirectX object
    
    if(g_D3D){
    
    g_D3D->Release();
    
    g_D3D=NULL;
    
    }
    
    }
    
     
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    
    {
    
    switch (message) {
    
    case WM_DESTROY:
    
    PostQuitMessage (0);
    
    return 0;
    
    }
    
    return DefWindowProc (hwnd, message, wParam, lParam );
    
    }

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    ... What are the errors it gives you ? That's important, you know.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Blackjack program, having problems with the ace
    By yigster in forum C Programming
    Replies: 6
    Last Post: 05-07-2009, 06:41 AM
  2. Replies: 19
    Last Post: 05-30-2007, 05:47 PM
  3. Problems with my c letter count program
    By cram55 in forum C Programming
    Replies: 10
    Last Post: 05-30-2007, 04:10 AM
  4. Program calculation problems?
    By rebel in forum C++ Programming
    Replies: 7
    Last Post: 11-28-2005, 03:31 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM