Solved

COM troubles

Posted on 2003-11-16
5
411 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

615 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