#### Archived

This topic is now archived and is closed to further replies.

# [Windows / VC++ .NET] calling CoInitializeEx?

This topic is 5213 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

1: I've never used COM much before, so please bear with me 2: I am trying to use a COM object, and I think that I have to call CoInitializeEx before I can call CoCreateInstance successfully. However, when I write  CoInitializeEx(NULL, COINIT_MULTITHREADED);  I get the errors: main.cpp(146) : error C2065: 'COINIT_MULTITHREADED' : undeclared identifier main.cpp(146) : error C3861: 'CoInitializeEx': identifier not found, even with argument-dependent lookup I have copied that line out of a tutorial. I looked up the function on MSDN and found the header file to be objbase.h, and I have also included that. IntelliSense seems to be able to find the declaration of both CoInitializeEx and COINIT_MULTITHREADED, because a parameter list pops up for CoInitializeEx and the actual definition pops up for COINIT_MULTITHREADED. Also, the compiler is NOT complaining that it cannot find objbase.h, and when I right click on #include <objbase.h> and view the file, I CAN find definitions for both of these things. I have also tried including everything that the tutorial (from the DX9 SDK) includes, to no avail. Does anyone know what might be going wrong? This is very frustrating Thanks for any help~ Riley Edit: PS: Those are the only 2 errors I get when I try to build. When I remove the call the project builds perfectly. [edited by - rileyriley on February 7, 2004 12:38:53 PM]

##### Share on other sites
upon a more careful reading of objbase.h, I figured out that I needed to include _WIN32_DCOM in my preprocesser definitions. Now it works fine - thanks for reading this anyway

##### Share on other sites
Thanks rileyriley. I was facing the same prob as you. Adding _WIN32_DCOM make my proj compilefine. But I am getting link errors. Did you face any such problems? I am trying to make a VC++ console application in VS.Net.

I get link errors for this piece of code:
HRESULT hr = CoCreateInstance(CLSID_CorDebug, NULL,
CLSCTX_INPROC_SERVER,
IID_ICorDebug,
(void **)&m_cor);

tryDebugCpp error LNK2020: unresolved token (0A00000C) IID_ICorDebug
tryDebugCpp error LNK2020: unresolved token (0A000010) CLSID_CorDebug
tryDebugCpp error LNK2020: unresolved token (0A000011) _CrtDbgReport
tryDebugCpp fatal error LNK1120: 3 unresolved externals

I would appreciate all the help

_Vinay_

[edited by - vinay on March 8, 2004 7:24:01 PM]

##### Share on other sites
I believe the COM stuff is defined in ole32.lib - I''m not sure about the crt debug stuff.

##### Share on other sites
Thanks again. Putting corguids.lib and ole32.lib did remove 2 of my link errors. But I still have one link error.

unresolved token (0A000011) _CrtDbgReport

I figured out that _CrtDbgReport is always called from within an #ifdef _DEBUG block. I removed the _DEBUG option from my compiler setting & the code compiled & linked file. However, need to find a better way.

_Vinay_

##### Share on other sites
just want to thank you too. today I had exactly the same problem as the original poster

However my problem didn''t get solved. But since I know it worked for the poster, I just started over from an empty project and then it worked. Previously I used the project wizard to create a console application using atl, and that didn''t work.

greets
matthias

• 38
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631365
• Total Posts
2999585
×