Solved

COM troubles

Posted on 2003-11-16
5
388 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
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

744 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

8 Experts available now in Live!

Get 1:1 Help Now