Solved

COM troubles

Posted on 2003-11-16
5
399 Views
Last Modified: 2013-11-25
I created an object that has a pointer to a com object as a datamember. I tried using CoInitializeEx() in the objects constructor and in the new thread where the object is instantiated.

It says it's an undeclared identifier or some such nonsense and flags everywhere I try to use it.

In another file in the same project though I've used the same object and it works fine. So it isn't a matter of having included the dlls wrong or having the wrong defines in stdafx.h

I have no experience with COM so I don't know what the problem might be. Maybe you guys have something for me to try?

Thanks,
-Sandra
0
Comment
Question by:Sandra-24
5 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 9760258
What COM object is it?  Perhaps you have forgotten to
    #import
the file with the information the compiler needs in order to recognize and understand the COM object.   Check the headers of the modules in which it works and see what's missing from the module that does not work.

Also, namespaces can cause trouble, for instance in particular with msxml interfaces... some places in the MFC libraries assume MSXML version 1and there are conflicts in you #import a newer version.

Please provide an example of the code that is failing and describe the error messages more exactly.  Thanks.

-- Dan
0
 
LVL 86

Expert Comment

by:jkr
ID: 9760647
>>having the wrong defines in stdafx.h

Just including stdafx.h might not be enough, as these might be project-specific. Hve you tried to

#define _WIN32_DCOM
#include <objbase.h>

directly?
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9761989
CoInitializeEx

Windows NT/2000: Requires Windows NT 4.0 or later.
Windows 95/98: Requires Windows 98 (or Windows 95 with DCOM).
Header: Declared in objbase.h.


According to these requirements, to compile CoInitializeEx call you need to have defined
_WIN32_WINNT >= 0x0400  (WinNT 4.0 or later)

or _WIN32_DCOM (DCOM installed).

These definitions should be placed before including of objbase.h.

0
 
LVL 3

Author Comment

by:Sandra-24
ID: 9767824
It turns out that another file included my header and thus placed it in the code above the #import statements.

Moving the #imports to the top of the file fixed it.

Thanks,
-Sandra
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9767896
Thanks for the points and the grade :)
I usually put the #import lines into stdafx.h since otherwise, the compiler will tend to repeatedly do the import -- which can be time-consuming with some large DLLs.

-- Dan
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question