Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COM Objects-error C2065,error C3861

Status
Not open for further replies.

PmtAce

Technical User
Apr 6, 2006
17
US
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;
}
 
I am using a windows xp and I tried defining _WIN32_DCOM in the beginning, but it didnt help.
 
I found this workspace with the original file that I am trying to recreate. I added it to my list of files and it solved that problem. However, I got a linking problem:
------ Rebuild All started: Project: Engine, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'Engine', configuration 'Debug|Win32'
Compiling...
Engine.cpp
Creating library...
Build log was saved at "file://l:\Actual\Game\Engine\Debug\BuildLog.htm"
Engine - 0 error(s), 0 warning(s)
------ Rebuild All started: Project: Test, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'Test', configuration 'Debug|Win32'
Compiling...
Main.cpp
Compiling manifest to resources...
Linking...
engine.lib(Engine.obj) : error LNK2019: unresolved external symbol __imp__DefWindowProcA@16 referenced in function "long __stdcall WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
engine.lib(Engine.obj) : error LNK2019: unresolved external symbol __imp__PostQuitMessage@4 referenced in function "long __stdcall WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
engine.lib(Engine.obj) : error LNK2019: unresolved external symbol __imp__CreateWindowExA@48 referenced in function "public: __thiscall Engine::Engine(struct EngineSetup *)" (??0Engine@@QAE@PAUEngineSetup@@@Z)
engine.lib(Engine.obj) : error LNK2019: unresolved external symbol __imp__CoInitializeEx@8 referenced in function "public: __thiscall Engine::Engine(struct EngineSetup *)" (??0Engine@@QAE@PAUEngineSetup@@@Z)
engine.lib(Engine.obj) : error LNK2019: unresolved external symbol __imp__RegisterClassExA@4 referenced in function "public: __thiscall Engine::Engine(struct EngineSetup *)" (??0Engine@@QAE@PAUEngineSetup@@@Z)
engine.lib(Engine.obj) : error LNK2019: unresolved external symbol __imp__LoadCursorA@8 referenced in function "public: __thiscall Engine::Engine(struct EngineSetup *)" (??0Engine@@QAE@PAUEngineSetup@@@Z)
engine.lib(Engine.obj) : error LNK2019: unresolved external symbol __imp__LoadIconA@8 referenced in function "public: __thiscall Engine::Engine(struct EngineSetup *)" (??0Engine@@QAE@PAUEngineSetup@@@Z)
engine.lib(Engine.obj) : error LNK2019: unresolved external symbol __imp__UnregisterClassA@8 referenced in function "public: virtual __thiscall Engine::~Engine(void)" (??1Engine@@UAE@XZ)
engine.lib(Engine.obj) : error LNK2019: unresolved external symbol __imp__CoUninitialize@0 referenced in function "public: virtual __thiscall Engine::~Engine(void)" (??1Engine@@UAE@XZ)
engine.lib(Engine.obj) : error LNK2019: unresolved external symbol __imp__DispatchMessageA@4 referenced in function "public: void __thiscall Engine::Run(void)" (?Run@Engine@@QAEXXZ)
engine.lib(Engine.obj) : error LNK2019: unresolved external symbol __imp__TranslateMessage@4 referenced in function "public: void __thiscall Engine::Run(void)" (?Run@Engine@@QAEXXZ)
engine.lib(Engine.obj) : error LNK2019: unresolved external symbol __imp__PeekMessageA@20 referenced in function "public: void __thiscall Engine::Run(void)" (?Run@Engine@@QAEXXZ)
engine.lib(Engine.obj) : error LNK2019: unresolved external symbol __imp__ShowWindow@8 referenced in function "public: void __thiscall Engine::Run(void)" (?Run@Engine@@QAEXXZ)
.\Debug/Test.exe : fatal error LNK1120: 13 unresolved externals
Build log was saved at "file://l:\Actual\Game\Test\Debug\BuildLog.htm"
Test - 14 error(s), 0 warning(s)
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========


I believe this means that it cant find the definiton of these files. The source program works so I have all the code. I guess that means I have not linked it to my project. I tried then adding the location of the files to the include directories and it still didnt work. Did I really fix the original problem and stumble on to another or is the original problem not fixed? Also, please tell me how to fix this.
 
Do you have ole32.lib in the list of libraries to link?
If adding that doesn't help, post your Linker Command Line options from your Project Settings and we'll see if anything else is missing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top