Sign in to follow this  
Hunter_Ex

Arghhh : ( Directx CreateDevice

Recommended Posts

Hunter_Ex    976
i have a really really strange problem so if anyone can see why this code is giving me errors when running this code shall run good what i know and the projects i made earlier runs gr8 and creates the D3D DEVICE but now i cant even CREATE A DEVICE :'(
#include <windows.h>
#include <d3dx9.h>

    LPDIRECT3D9 d3d;
   D3DDISPLAYMODE screen;
   D3DPRESENT_PARAMETERS params;
   LPDIRECT3DDEVICE9 graphDevice;   

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);
    
    
    
       



   HRESULT res;
   
   d3d = Direct3DCreate9( D3D_SDK_VERSION );
   d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&screen);
    
   ZeroMemory( &params, sizeof(params) );
   params.SwapEffect = D3DSWAPEFFECT_DISCARD;
   params.BackBufferCount = 1; 
   params.hDeviceWindow = hwnd;
   params.Windowed = true;
   params.BackBufferFormat = D3DFMT_UNKNOWN;
   
   
   //params.EnableAutoDepthStencil = false;
   //params.AutoDepthStencilFormat = D3DFMT_D16;


   if (FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,
   D3DCREATE_HARDWARE_VERTEXPROCESSING,&params,&graphDevice)))
   {
      MessageBox(hwnd,"no hardware vertex","",0);                                                         
      res = d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,
      D3DCREATE_SOFTWARE_VERTEXPROCESSING,&params,&graphDevice);
      
      if (res = D3DERR_INVALIDCALL) MessageBox(hwnd,"big error","",0);



   };
   


    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

how to make the script into a little scroll window??? thx hunter_ex [Edited by - Hunter_Ex on July 18, 2005 7:19:18 PM]

Share this post


Link to post
Share on other sites
xsirxx    170
Whats the error?
----
pAdapterInfo is of type D3DAdapterInfo. Lookup how to set it up if ya need it.

params.BackBufferWidth = 544;
params.BackBufferHeight = 375;
params.BackBufferFormat = pAdapterInfo->d3ddmDesktop.Format;

Hope this helps.

Share this post


Link to post
Share on other sites
Hunter_Ex    976
the error is that i get D3DERR_INVALIDCALL on createDevice : (

that shall not happen ive made alot of d3d apps
something strange has happen

the D3DFMT_UNKNOWN / i tryed replace it with screen.Format;

but with no succes

plzz help

Share this post


Link to post
Share on other sites
Agony    3452
First, use [source][/source] to get a white syntax-highlighted box with a scrollbar, or [code][/code] to merely get a fixed-width font. (Beware, lines won't autowrap, and will make your post really wide if you have long lines.)

As for what's wrong, unfortunately I can't see anything offhand. But if you enable the debug version of the DirectX runtime, it might very likely tell you more about your problem. Should be in the DirectX properties found in the control panel. Go to the Direct3D tab in those settings, and you should be able to switch between the retail and debug version, and change the debug output level, in order to get more information on things that are occurring. Might help a lot.

Share this post


Link to post
Share on other sites
Hunter_Ex    976
okay trough the debugger i found out that te window handle was "0x0"

but how can it be that if i create then window in the same event as i create the device in the time?? with the same window??

Share this post


Link to post
Share on other sites
Hunter_Ex    976
ohh yea i got it to work

the problem was that the window i supplied was not correctly derived from the parent class so it used a 0x0 window witch causes crash

:/

thanx for helping

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this