Solved

COM troubles

Posted on 2003-11-16
5
391 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now