Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

COM troubles

Posted on 2003-11-16
5
Medium Priority
?
421 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

664 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