Original Post
I am trying to compile my own copy of a tutorial that I am going through and I am having 2 compile issues. The program tutorial's source code will compile without error. However, I can't get my project in the same IDE (VC++ 2005) to recognize COM's. 1)In the tutorial's "working" .cpp file, they Initialize the COM using multithreaded concurrency (as they state it). However, using the same IDE, it is not regonizing those COM functions or arguments. I obviously have by IDE setup correctly (hence the reason it compiles when I load the tutorials project). Mainly these following lines which you will find in the main code .cpp listed below: I have also thoroughly examined the include declaratives, so I don't know where my problem is: This is all with the use of DIRECTX9. Below is the "working" tutorial code: .cpp and .h .cpp file This is my .h file This is my .CPP file 2) It keeps tell me that the initiation of the WNDCLASSEX struct member structname.lpszClassName = "WindowClass"; error C2440: '=' : cannot convert from 'const char [12]' to 'LPCWSTR I don't see what I am doing wrong here. The following are the error messages Any suggestions?
// Initialise the COM using multithreaded concurrency.
CoInitializeEx( NULL, COINIT_MULTITHREADED );
...
...
...
// Uninitialise the COM.
CoUninitialize();
//-----------------------------------------------------------------------------
// The primary engine header file. This file links the entire engine together
// and is the only header file that needs to be included in any project using
// the engine.
//
// Programming a Multiplayer First Person Shooter in DirectX
// Copyright (c) 2004 Vaughan Young
//-----------------------------------------------------------------------------
#ifndef ENGINE_H
#define ENGINE_H
//-----------------------------------------------------------------------------
// DirectInput Version Define
//-----------------------------------------------------------------------------
#define DIRECTINPUT_VERSION 0x0800
//-----------------------------------------------------------------------------
// System Includes
//-----------------------------------------------------------------------------
#include <stdio.h>
#include <tchar.h>
#include <windowsx.h>
//-----------------------------------------------------------------------------
// DirectX Includes
//-----------------------------------------------------------------------------
#include <d3dx9.h>
#include <dinput.h>
#include <dplay8.h>
#include <dmusici.h>
//-----------------------------------------------------------------------------
// Macros
//-----------------------------------------------------------------------------
#define SAFE_DELETE( p ) { if( p ) { delete ( p ); ( p ) = NULL; } }
#define SAFE_DELETE_ARRAY( p ) { if( p ) { delete[] ( p ); ( p ) = NULL; } }
#define SAFE_RELEASE( p ) { if( p ) { ( p )->Release(); ( p ) = NULL; } }
//-----------------------------------------------------------------------------
// Engine Includes
//-----------------------------------------------------------------------------
#include "LinkedList.h"
#include "ResourceManagement.h"
#include "Geometry.h"
//-----------------------------------------------------------------------------
// Engine Setup Structure
//-----------------------------------------------------------------------------
struct EngineSetup
{
HINSTANCE instance; // Application instance handle.
char *name; // Name of the application.
//-------------------------------------------------------------------------
// The engine setup structure constructor.
//-------------------------------------------------------------------------
EngineSetup()
{
instance = NULL;
name = "Application";
}
};
//-----------------------------------------------------------------------------
// Engine Class
//-----------------------------------------------------------------------------
class Engine
{
public:
Engine( EngineSetup *setup = NULL );
virtual ~Engine();
void Run();
HWND GetWindow();
void SetDeactiveFlag( bool deactive );
private:
bool m_loaded; // Indicates if the engine is loading.
HWND m_window; // Main window handle.
bool m_deactive; // Indicates if the application is active or not.
EngineSetup *m_setup; // Copy of the engine setup structure.
};
//-----------------------------------------------------------------------------
// Externals
//-----------------------------------------------------------------------------
extern Engine *g_engine;
#endif
//-----------------------------------------------------------------------------
// Engine.h implementation.
// Refer to the Engine.h interface for more details.
//-----------------------------------------------------------------------------
#include "Engine.h"
//-----------------------------------------------------------------------------
// Globals
//-----------------------------------------------------------------------------
Engine *g_engine = NULL;
//-----------------------------------------------------------------------------
// Handles Windows messages.
//-----------------------------------------------------------------------------
LRESULT CALLBACK WindowProc( HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
switch( msg )
{
case WM_ACTIVATEAPP:
g_engine->SetDeactiveFlag( !wparam );
return 0;
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
default:
return DefWindowProc( wnd, msg, wparam, lparam );
}
}
//-----------------------------------------------------------------------------
// The engine class constructor.
//-----------------------------------------------------------------------------
Engine::Engine( EngineSetup *setup )
{
// Indicate that the engine is not yet loaded.
m_loaded = false;
// If no setup structure was passed in, then create a default one.
// Otehrwise, make a copy of the passed in structure.
m_setup = new EngineSetup;
if( setup != NULL )
memcpy( m_setup, setup, sizeof( EngineSetup ) );
// Store a pointer to the engine in a global variable for easy access.
g_engine = this;
// Prepare and register the window class.
WNDCLASSEX wcex;
wcex.cbSize = sizeof( WNDCLASSEX );
wcex.style = CS_CLASSDC;
wcex.lpfnWndProc = WindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = m_setup->instance;
wcex.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "WindowClass";
wcex.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
RegisterClassEx( &wcex );
// Initialise the COM using multithreaded concurrency.
CoInitializeEx( NULL, COINIT_MULTITHREADED );
// Create the window and retrieve a handle to it.
// Note: Later the window will be created using a windowed/fullscreen flag.
m_window = CreateWindow( "WindowClass", m_setup->name, WS_OVERLAPPED, 0, 0, 800, 600, NULL, NULL, m_setup->instance, NULL );
// Seed the random number generator with the current time.
srand( timeGetTime() );
// The engine is fully loaded and ready to go.
m_loaded = true;
}
//-----------------------------------------------------------------------------
// The engine class destructor.
//-----------------------------------------------------------------------------
Engine::~Engine()
{
// Ensure the engine is loaded.
if( m_loaded == true )
{
// Everything will be destroyed here (such as the DirectX components).
}
// Uninitialise the COM.
CoUninitialize();
// Unregister the window class.
UnregisterClass( "WindowClass", m_setup->instance );
// Destroy the engine setup structure.
SAFE_DELETE( m_setup );
}
//-----------------------------------------------------------------------------
// Enters the engine into the main processing loop.
//-----------------------------------------------------------------------------
void Engine::Run()
{
// Ensure the engine is loaded.
if( m_loaded == true )
{
// Show the window.
ShowWindow( m_window, SW_NORMAL );
// Enter the message loop.
MSG msg;
ZeroMemory( &msg, sizeof( MSG ) );
while( msg.message != WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else if( !m_deactive )
{
// Calculate the elapsed time.
unsigned long currentTime = timeGetTime();
static unsigned long lastTime = currentTime;
float elapsed = ( currentTime - lastTime ) / 1000.0f;
lastTime = currentTime;
}
}
}
// Destroy the engine.
SAFE_DELETE( g_engine );
}
//-----------------------------------------------------------------------------
// Returns the window handle.
//-----------------------------------------------------------------------------
HWND Engine::GetWindow()
{
return m_window;
}
//-----------------------------------------------------------------------------
// Sets the deactive flag.
//-----------------------------------------------------------------------------
void Engine::SetDeactiveFlag( bool deactive )
{
m_deactive = deactive;
}
//-----------------------------------------------------------------------------
// The primary engine header file. This file links the entire engine together
// and is the only header file that needs to be included in any project using
// the engine.
//
// Programming a Multiplayer First Person Shooter in DirectX
// Copyright (c) 2004 Vaughan Young
//-----------------------------------------------------------------------------
#ifndef ENGINE_H
#define ENGINE_H
//-----------------------------------------------------------------------------
// DirectInput Version Define
//-----------------------------------------------------------------------------
#define DIRECTINPUT_VERSION 0x0800
//-----------------------------------------------------------------------------
// System Includes
//-----------------------------------------------------------------------------
#include <stdio.h>
#include <tchar.h>
#include <windowsx.h>
//-----------------------------------------------------------------------------
// DirectX Includes
//-----------------------------------------------------------------------------
#include <d3dx9.h>
#include <dinput.h>
#include <dplay8.h>
#include <dmusici.h>
//-----------------------------------------------------------------------------
// Macros
//-----------------------------------------------------------------------------
#define SAFE_DELETE( p ) { if( p ) { delete ( p ); ( p ) = NULL; } }
#define SAFE_DELETE_ARRAY( p ) { if( p ) { delete[] ( p ); ( p ) = NULL; } }
#define SAFE_RELEASE( p ) { if( p ) { ( p )->Release(); ( p ) = NULL; } }
//-----------------------------------------------------------------------------
// Engine Includes
//-----------------------------------------------------------------------------
#include "LinkedList.h"
#include "ResourceManagement.h"
#include "Geometry.h"
//-----------------------------------------------------------------------------
// Engine Setup Structure
//-----------------------------------------------------------------------------
struct EngineSetup
{
HINSTANCE instance; // Application instance handle.
char *name; // Name of the application.
//-------------------------------------------------------------------------
// The engine setup structure constructor.
//-------------------------------------------------------------------------
EngineSetup()
{
instance = NULL;
name = "Application";
}
};
//-----------------------------------------------------------------------------
// Engine Class
//-----------------------------------------------------------------------------
class Engine
{
public:
Engine( EngineSetup *setup = NULL );
virtual ~Engine();
void Run();
HWND GetWindow();
void SetDeactiveFlag( bool deactive );
private:
bool m_loaded; // Indicates if the engine is loading.
HWND m_window; // Main window handle.
bool m_deactive; // Indicates if the application is active or not.
EngineSetup *m_setup; // Copy of the engine setup structure.
};
//-----------------------------------------------------------------------------
// Externals
//-----------------------------------------------------------------------------
extern Engine *g_engine;
#endif
//-----------------------------------------------------------------------------
// Engine.h implementation.
// Refer to the Engine.h interface for more details.
//
// Programming a Multiplayer First Person Shooter in DirectX
// Copyright (c) 2004 Vaughan Young
//-----------------------------------------------------------------------------
#include "Engine.h"
//-----------------------------------------------------------------------------
// Globals
//-----------------------------------------------------------------------------
Engine *g_engine = NULL;
//-----------------------------------------------------------------------------
// Handles Windows messages.
//-----------------------------------------------------------------------------
LRESULT CALLBACK WindowProc( HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
switch( msg )
{
case WM_ACTIVATEAPP:
g_engine->SetDeactiveFlag( !wparam );
return 0;
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
default:
return DefWindowProc( wnd, msg, wparam, lparam );
}
}
//-----------------------------------------------------------------------------
// The engine class constructor.
//-----------------------------------------------------------------------------
Engine::Engine( EngineSetup *setup )
{
// Indicate that the engine is not yet loaded.
m_loaded = false;
// If no setup structure was passed in, then create a default one.
// Otehrwise, make a copy of the passed in structure.
m_setup = new EngineSetup;
if( setup != NULL )
memcpy( m_setup, setup, sizeof( EngineSetup ) );
// Store a pointer to the engine in a global variable for easy access.
g_engine = this;
// Prepare and register the window class.
WNDCLASSEX wcex;
wcex.cbSize = sizeof( WNDCLASSEX );
wcex.style = CS_CLASSDC;
wcex.lpfnWndProc = WindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = m_setup->instance;
wcex.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "WindowClass";
wcex.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
RegisterClassEx( &wcex );
// Initialise the COM using multithreaded concurrency.
CoInitializeEx( NULL, COINIT_MULTITHREADED );
// Create the window and retrieve a handle to it.
// Note: Later the window will be created using a windowed/fullscreen flag.
m_window = CreateWindow( "WindowClass", m_setup->name, WS_OVERLAPPED, 0, 0, 800, 600, NULL, NULL, m_setup->instance, NULL );
// Seed the random number generator with the current time.
srand( timeGetTime() );
// The engine is fully loaded and ready to go.
m_loaded = true;
}
//-----------------------------------------------------------------------------
// The engine class destructor.
//-----------------------------------------------------------------------------
Engine::~Engine()
{
// Ensure the engine is loaded.
if( m_loaded == true )
{
// Everything will be destroyed here (such as the DirectX components).
}
// Uninitialise the COM.
CoUninitialize();
// Unregister the window class.
UnregisterClass( "WindowClass", m_setup->instance );
// Destroy the engine setup structure.
SAFE_DELETE( m_setup );
}
//-----------------------------------------------------------------------------
// Enters the engine into the main processing loop.
//-----------------------------------------------------------------------------
void Engine::Run()
{
// Ensure the engine is loaded.
if( m_loaded == true )
{
// Show the window.
ShowWindow( m_window, SW_NORMAL );
// Enter the message loop.
MSG msg;
ZeroMemory( &msg, sizeof( MSG ) );
while( msg.message != WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else if( !m_deactive )
{
// Calculate the elapsed time.
unsigned long currentTime = timeGetTime();
static unsigned long lastTime = currentTime;
float elapsed = ( currentTime - lastTime ) / 1000.0f;
lastTime = currentTime;
}
}
}
// Destroy the engine.
SAFE_DELETE( g_engine );
}
//-----------------------------------------------------------------------------
// Returns the window handle.
//-----------------------------------------------------------------------------
HWND Engine::GetWindow()
{
return m_window;
}
//-----------------------------------------------------------------------------
// Sets the deactive flag.
//-----------------------------------------------------------------------------
void Engine::SetDeactiveFlag( bool deactive )
{
m_deactive = deactive;
}
...\projects\engine\engine\engine.cpp(64) : error C2440: '=' : cannot convert from 'const char [12]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
...\projects\engine\engine\engine.cpp(69) : error C2065: 'COINIT_MULTITHREADED' : undeclared identifier
...\projects\engine\engine\engine.cpp(69) : error C3861: 'CoInitializeEx': identifier not found
...\projects\engine\engine\engine.cpp(73) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [12]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
...\projects\engine\engine\engine.cpp(97) : error C2664: 'UnregisterClassW' : cannot convert parameter 1 from 'const char [12]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast