Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7705209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:49:21+00:00 2026-05-31T23:49:21+00:00

I am trying to initialize directX, but for some reason it can’t create d3d

  • 0

I am trying to initialize directX, but for some reason it can’t create d3d device.
It compiles properly, but shows last messagebox (“Can’t create D3D device”)

While debugging:
– d3dObject 0x00000000 IDirect3D9 *
– IUnknown {…} IUnknown
__vfptr CXX0030: Error: expression cannot be evaluated

#include <d3d9.h>
#include <d3dx9.h>
#include <windows.h>

HWND hMainWindow;

IDirect3D9 *d3dObject = 0;
IDirect3DDevice9 *d3dDevice = 0;

bool InitDirectX()
{
    d3dObject = Direct3DCreate9(D3D_SDK_VERSION);
    if( !d3dObject )
    {
        MessageBox(0, "Can't create Direct3D Object", "Error", MB_ICONSTOP);
        PostQuitMessage(0);
    }

    D3DDISPLAYMODE mode;
    d3dObject->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode);
    d3dObject->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, mode.Format, mode.Format, true);
    d3dObject->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, false);

    D3DCAPS9 caps;
    d3dObject->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);

    DWORD devBehaviorFlags = 0;
    if( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
          devBehaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
    else
          devBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;

    // If pure device and HW T&L supported
    if( caps.DevCaps & D3DDEVCAPS_PUREDEVICE &&
          devBehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING)
                devBehaviorFlags |= D3DCREATE_PUREDEVICE;

    D3DPRESENT_PARAMETERS d3dpp;
    d3dpp.BackBufferWidth            = 800;
    d3dpp.BackBufferHeight           = 600;
    d3dpp.BackBufferFormat           = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferCount            = 1;
    d3dpp.MultiSampleType            = D3DMULTISAMPLE_NONE;
    d3dpp.MultiSampleQuality         = 0;
    d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD;
    d3dpp.hDeviceWindow              = hMainWindow;
    d3dpp.Windowed                   = true;
    d3dpp.EnableAutoDepthStencil     = true;
    d3dpp.AutoDepthStencilFormat     = D3DFMT_D24S8;
    d3dpp.Flags                      = 0;
    d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
    d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;


    if(!d3dObject->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hMainWindow, devBehaviorFlags, &d3dpp, &d3dDevice))
    {
        ::MessageBox(0, "Can't create D3D device", "Error", MB_ICONSTOP);
        return false;
    }

    return true;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:49:21+00:00Added an answer on May 31, 2026 at 11:49 pm

    IDirect3D9::CreateDevice returns a HRESULT not a bool.
    The correct way to check if the device has been created is to use the SUCCEEDED or FAILED macros:

    HRESULT hr = d3dObject->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hMainWindow, devBehaviorFlags, &d3dpp, &d3dDevice);
    if( FAILED(hr) )
    {
        // hr will be one of the D3DERR_ values
        ::MessageBox(0, "Can't create D3D device", "Error", MB_ICONSTOP);
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to initialize a static class, with an argument, and then run some
I am trying to initialize an NSMutableArray with the values of an NSArray but
I'm trying to initialize a dict variable but I don't understand why one way
I am trying to initialize the following array of the following struct, but my
I'm trying to initialize my data in my Azure Data Tables but I only
I'm trying initialize my local rails server but I haven't been able to, because
I am trying to initialize NSDictionary but it gives me following error: Program received
I'm trying to initialize the last element in the array int grades[10]; to grade
I have a class Flight, and I'm trying initialize it, but I have a
I am trying to initialize a class variable as a hash when I create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.