Im creating a program using COM objects. I am getting a compile error saying:
.\Engine.cpp(72) : error C2065: 'COINIT_MULTITHREADED' : undeclared identifier
.\Engine.cpp(72) : error C3861: 'CoInitializeEx': identifier not found
Because it is saying it is undeclared I am asuming that it means a header file isnt being included. I tried other forums and found adding <objbase.h> or #define _WIN32_WINNT 0x0400 did not help. Please tell me what the problem is exactly and how to fix it. If it really is just adding a header file, could u give me the filename and path. Thanks in advance. Below is the complete code for this section:
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#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, 100, 800, 800, 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;
}
.\Engine.cpp(72) : error C2065: 'COINIT_MULTITHREADED' : undeclared identifier
.\Engine.cpp(72) : error C3861: 'CoInitializeEx': identifier not found
Because it is saying it is undeclared I am asuming that it means a header file isnt being included. I tried other forums and found adding <objbase.h> or #define _WIN32_WINNT 0x0400 did not help. Please tell me what the problem is exactly and how to fix it. If it really is just adding a header file, could u give me the filename and path. Thanks in advance. Below is the complete code for this section:
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#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, 100, 800, 800, 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;
}