Thread: Having some trouble setting up Dev-c++ for DX

  1. #1
    Wen Resu
    Join Date
    May 2003
    Posts
    219

    Having some trouble setting up Dev-c++ for DX

    Ok heres my trouble. i am using a tutorial i got. its very comprehensive and full of great setup information... if i was using MSVC++.
    I am using Dev c++ for my Compiler, and i have been trying to set it up for DX.
    i've told it where the DX include folder is,
    added a call for -fvtable-thunks when it compiles. and nothing more so far. with the suplied code it get the following errors
    c:\documents and settings\stephen\my documents\c++\direct x 8\test.cpp:146: ANSI C++ forbids implicit conversion from `void *' in argument passing

    c:\documents and settings\stephen\my documents\c++\direct x 8\test.cpp:161: ANSI C++ forbids implicit conversion from `void *' in argument passing

    I see this as it saying i can't pass a void dereferencer to the function,. if this a problem with the code <direct copy/paste> or have i not finished setting up Dev-C++. I've look on board threw the seach and on google, most tutorials and help i found was for MSVC++ and not dev-c++
    I'm suplying the code in case theres a problem with it or something to that effect.
    Thanks a lot for nay help.



    Code:
    #include <d3d8.h>
    
    LPDIRECT3D8 g_pD3D = NULL;
    LPDIRECT3DDEVICE8 g_pD3DDevice = NULL;
    
    HRESULT InitialiseD3D(HWND hWnd)
    {
        //First of all, create the main D3D object. If it is created successfully we
        //should get a pointer to an IDirect3D8 interface.
        g_pD3D = Direct3DCreate8(D3D_SDK_VERSION);
        if(g_pD3D == NULL)
        {
            return E_FAIL;
        }
    
        //Get the current display mode
        D3DDISPLAYMODE d3ddm;
        if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
        {
            return E_FAIL;
        }
    
        //Create a structure to hold the settings for our device
        D3DPRESENT_PARAMETERS d3dpp;
        ZeroMemory(&d3dpp, sizeof(d3dpp));
    
        //Fill the structure.
        //We want our program to be windowed, and set the back buffer to a format
        //that matches our current display mode
        d3dpp.Windowed = TRUE;
        d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
        d3dpp.BackBufferFormat = d3ddm.Format;
    
        //Create a Direct3D device.
        if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                       D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice)))
        {
            return E_FAIL;
        }
        
        return S_OK;
    }
    
    void Render()
    {
        if(g_pD3DDevice == NULL)
        {
            return;
        }
    
        //Clear the backbuffer to a green color
        g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);
        
        //Begin the scene
        g_pD3DDevice->BeginScene();
        
        //Rendering of our game objects will go here
        
        //End the scene
        g_pD3DDevice->EndScene();
        
        //Filp the back and front buffers so that whatever has been rendered on the back buffer
        //will now be visible on screen (front buffer).
        g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
    }
    
    void CleanUp()
    {
        if(g_pD3DDevice != NULL)
        {
            g_pD3DDevice->Release();
            g_pD3DDevice = NULL;
        }
    
        if(g_pD3D != NULL)
        {
            g_pD3D->Release();
            g_pD3D = NULL;
        }
    }
    
    void GameLoop()
    {
        //Enter the game loop
        MSG msg;
        BOOL fMessage;
    
        PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
        
        while(msg.message != WM_QUIT)
        {
            fMessage = PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE);
    
            if(fMessage)
            {
                //Process message
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
            else
            {
                //No message to process, so render the current scene
                Render();
            }
    
        }
    }
    
    //The windows message handler
    LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
            case WM_DESTROY:
                PostQuitMessage(0);
                return 0;
            break;
            case WM_KEYUP:
                switch (wParam)
                {
                    case VK_ESCAPE:
                        //User has pressed the escape key, so quit
                        DestroyWindow(hWnd);
                        return 0;
                    break;
                }
            break;
    
        }
    
        return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    
    //Application entry point
    INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
    {
        //Register the window class
        WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L,
                         GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                         "DX Project 1", NULL};
        RegisterClassEx(&wc);
    
        //Create the application's window
        HWND hWnd = CreateWindow("DX Project 1", "www.andypike.com: Tutorial 1",
                                  WS_OVERLAPPEDWINDOW, 50, 50, 500, 500,
                                  GetDesktopWindow(), NULL, wc.hInstance, NULL); 
    
        //Initialize Direct3D
        if(SUCCEEDED(InitialiseD3D(hWnd)))
        {
            //Show our window
            ShowWindow(hWnd, SW_SHOWDEFAULT);
            UpdateWindow(hWnd);
    
            //Start game running: Enter the game loop
            GameLoop();
        }
        
        CleanUp();
    UnregisterClass("DX Project 1", wc.hInstance); 
        
        return 0;
    }
    EDIT:: To highlight the errors
    Last edited by Iamien; 08-25-2003 at 05:54 PM.

  2. #2
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    just as a note. i am using the dll and configuration instruction found in the read me of the directx files from http://www.bloodshed.net/dev/packages/

  3. #3
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    Please copy and paste the exact compiler log. DevC++ unfortunatly cuts off the end of the compilers errormessages in the "compiler" tab. They are intact in the "compile log" tab.

    The highlighted lines do not contain any mistakes.
    [code]

    your code here....

    [/code]

  4. #4
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    here you go. thanks for your time. <i tohugh the code looked fine..>
    in the first on it doesn't like the last null
    and in second one, it doesn't like the second parameter wc.Hintance


    c:\documents and settings\stephen\my documents\c++\direct x 8\test.cpp: In function `int WinMain(HINSTANCE__ *, HINSTANCE__ *, CHAR *, int)':
    c:\documents and settings\stephen\my documents\c++\direct x 8\test.cpp:150: ANSI C++ forbids implicit conversion from `void *' in argument passing
    c:\documents and settings\stephen\my documents\c++\direct x 8\test.cpp:166: ANSI C++ forbids implicit conversion from `void *' in argument passing
    Last edited by Iamien; 08-25-2003 at 06:27 PM.

  5. #5
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    AHH the solution was simple
    I'm on XP, and in both calls, wc.hInstance should be set to NULL as irts ignore in NT!
    god bless the msdn
    thanks for help, your saying that code was fine made me think, i think the problem is with final null, but what if its just because when i split it into multiple lines it just reports problem for last paramter of function. i quickly looked over to a normsal windows app i saw i used null there, then reference MSDN to see why
    Last edited by Iamien; 08-25-2003 at 07:09 PM.

  6. #6
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    edit: ok =)
    [code]

    your code here....

    [/code]

  7. #7
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    Uhm... well at a second thought... that can't really be the problem because I use hInstance in my code, too. I think the problem is....

    Code:
        WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L,
                         GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                         "DX Project 1", NULL};
    I think you are not allowed to use function return values in an initializer.
    You "solved" the problem by removing GetModulehandle.

    This code uses hInstance and it runs on WinXP (don't copy it, it's meant to be used by RegisterClass and not RegisterClassEx)

    Code:
    	p->hInstance= GetModuleHandle(NULL);
    
    	wc.style=         CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    	wc.lpfnWndProc=   WndProc;
    	wc.cbClsExtra=    0;
    	wc.cbWndExtra=    0;
    	wc.hInstance=     p->hInstance;
    	wc.hIcon=         LoadIcon(NULL, IDI_WINLOGO);
    	wc.hCursor=       LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground= NULL;
    	wc.lpszMenuName=  NULL;
    	wc.lpszClassName= "BlackMagic";
    
    	if (!RegisterClass(&wc)) {
    		MessageBox(NULL,"Failed To Register The Window Class.","ERROR", MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;
    	}
    which means it's ok to pass an instance, windows XP just ignores it. Try to set hInstance outside of the initializer (set it to NULL in the { } and then add wc.hInstance= GetModuleHandle(NULL);. Otherwise you'll probably get into problems on non-XP Windows'.
    [code]

    your code here....

    [/code]

  8. #8
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    Got it, thansk a lot.
    What i did was i called
    HINSTANCE Ninst = GetModuleHandel(NULL)
    and used that when ever i need in Handel. words like a charm

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to Dev C++/<windows.h>...
    By Cilius in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2005, 01:05 AM
  2. Glut and Dev C++, Programs not Quitting?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-29-2004, 08:43 PM
  3. Your favourite fantasy game setting?
    By fry in forum Game Programming
    Replies: 4
    Last Post: 10-16-2002, 06:26 AM
  4. trouble with dev c++
    By Klinerr1 in forum C Programming
    Replies: 6
    Last Post: 06-14-2002, 11:14 PM
  5. Having trouble correctly setting DJGPP's env. variables in XP
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 06-05-2002, 10:51 PM