Sign in to follow this  
Chad Smith

DirectX not setting up?

Recommended Posts

First off I must say that I am a newb to Visual C++ Express Edition and DirectX. I have a problem setting up DirectX. I follow a tutorial on how to set it up, but it won't work. It dosen't seem like I am getting DirectX errors though. It seems like I am getting errors from the Platform SDK (which makes no since because I can build a stand alone Win32 Application already). I will post my code, just incase there is something wrong with it (I did look through... I didn't see anything), then I will post my build log.
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

Title : WinMain.cpp
Author : Chad Vernon
URL : http://www.c-unit.com

Description : Creating a Window

Created :  08/09/2005
Modified : 08/11/2005

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "stdafx.h"
#include "WinMain.h"

#define WINDOW_TITLE "Creating a Window"
#define WINDOW_WIDTH 300
#define WINDOW_HEIGHT 300

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR cmdLine, int cmdShow )
{ 
	// Define the window
    WNDCLASSEX wcex;
    wcex.cbSize         = sizeof( WNDCLASSEX ); 
    wcex.style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = NULL;
    wcex.hCursor        = LoadCursor( hInstance, IDC_ARROW );
    wcex.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = WINDOW_TITLE;
    wcex.hIconSm        = NULL;

	// Register the window
    RegisterClassEx( &wcex );

	// Create the window
    HWND hWnd = CreateWindow( WINDOW_TITLE, WINDOW_TITLE, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, hInstance, 0 );
    
    // Adjust to actual desired size
    RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT };
    AdjustWindowRect( &rect, GetWindowLong( hWnd, GWL_STYLE ), FALSE );
    SetWindowPos( hWnd, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE  );

    ShowWindow( hWnd, SW_SHOW );
    UpdateWindow( hWnd );

	//Create the DirectX Object
	LPDIRECT3D9 pD3D9=Direct3DCreate9(D3D_SDK_VERSION);
	//if it can not create the object, then tell me what the error was
	if(!pD3D9)
	{
		MessageBox(0, "Direct3DCreate9()-FAILED", 0, 0);
		return 0;
	}
	//now we need to create the presentation parameters
	//and fill them out
	D3DPRESENT_PARAMETERS D3DPP;
	ZeroMemory(&D3DPP, sizeof(D3DPP));
	//make the application windowed
	D3DPP.Windowed=TRUE;
	D3DPP.SwapEffect=D3DSWAPEFFECT_DISCARD;

	//now it's time to create a Direct3D Device
	//the device is very important
    LPDIRECT3DDEVICE9 pD3DDevice9=NULL;
	//checks to see if it failed creating the Direct3D Device
	//if so, print out that it did
	if(FAILED(pD3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&D3Dpp, &pD3DDevice)))
	{
		MessageBox(0, "CreateDevice()-FAILED", 0, 0)
		SAFE_RELEASE(pD3D9);
		return 0;
	}


    // Main loop
    MSG msg;
    while ( 1 ) 
    {
        // Only render when there are no messages
        if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) 
        {
            if ( msg.message == WM_QUIT)
            {
                break;
            }
            TranslateMessage( &msg );
            DispatchMessage ( &msg );
        } 
        else 
        {
			//before we render clear the screen
			pD3DDevice->Clear(0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 100, 0), 1.0f, 0);
			//beging the scene now
			pD3DDevice->BeginScene();
            // Render a frame
			//end the scene
			pD3DDevice->EndScene();
			//now present the scene to the user
			pD3DDevice->Present(0, 0, 0, 0);
			
        } 
    }
	//now give back the resources
	SAFE_RELEASE(pD3DDevice);
	SAFE_RELEASE(pD3D9);
    
	return 0;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Summary: Application event handler.
Parameters:
    [in] hWnd - Unique handle to the window.
    [in] message - Incoming message.
    [in] wParam - Parameter of the message (unsigned int).
    [in] lParam - Parameter of the message (long).
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    switch ( message ) 
    {
    case WM_DESTROY:
        PostQuitMessage( 0 );
        return 0;
    case WM_PAINT:
        // Render a frame then validate the client area
        ValidateRect( hWnd, 0 );
        return 0;
    }

    return DefWindowProc( hWnd, message, wParam, lParam );
}

and my build log:
------ Build started: Project: WindowCreation, Configuration: Debug Win32 ------
Compiling...
stdafx.cpp
c:\program files\microsoft platform sdk for windows server 2003 r2\include\winnt.h(222) : error C2146: syntax error : missing ';' before identifier 'PVOID64'
c:\program files\microsoft platform sdk for windows server 2003 r2\include\winnt.h(222) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\program files\microsoft platform sdk for windows server 2003 r2\include\winnt.h(5940) : error C2146: syntax error : missing ';' before identifier 'Buffer'
c:\program files\microsoft platform sdk for windows server 2003 r2\include\winnt.h(5940) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\program files\microsoft platform sdk for windows server 2003 r2\include\winnt.h(5940) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Build log was saved at "file://c:\Documents and Settings\Chad\My Documents\Visual Studio 2005\Projects\DirectX1-Window\CU_WindowCreation\CU_WindowCreation\Debug\BuildLog.htm"
WindowCreation - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Do y'all see any stupid error mistakes? yes, I did add the DirectX stuff to the VC++ Directories, and I did add the needed libs in my project settings. Can anyone please help me? Like I said, I can build a stand alone Win32 Application just fine. Thanks to all who help!! Chad

Share this post


Link to post
Share on other sites
sure.

stdafx.h


// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

// Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN

// Useful macros
#define SAFE_RELEASE(x) if( x ) { (x)->Release(); (x) = NULL; }
#define SAFE_DELETE(x) if( x ) { delete(x); (x) = NULL; }
#define SAFE_DELETE_ARRAY(x) if( x ) { delete [] (x); (x) = NULL; }

// Windows Header Files:
#include <windows.h>

// C RunTime Header Files
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>

//DirectX Header Files
#include <d3d9.h>
#include <d3dx9.h>



and winmain.h


#ifndef WINMAIN_H
#define WINMAIN_H


LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );

#endif



Hopefully you/y'all (if anyone else comes and helps) can figure this out!

Chad.

Share this post


Link to post
Share on other sites
I wanted to stay away from bumping this for as long as I can, but it is almost off the first page, and I don't want it to get lost.


can anyone please help me?

Chad.

Share this post


Link to post
Share on other sites
I did what you said, and I got the exact same errors. :(. Nice try though.

Anyone else?

Chad.


EDIT: I have kind of traced down the error. I just went and tried to build a plain Win32 Application, and it didn't build. It had the same errors as my DX Application. Then I went to the VC++ Directories and took off the DX includes there, and the library files there and it can compile a regular win32 app just fine. Why can't it build one with the DX includes setup? Anyone know what is going on?

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