Solved

Objects in COM

Posted on 2002-03-25
6
188 Views
Last Modified: 2013-11-25
Is there a way to pass a non-COM object (an object created outside of the COM object) through an interface where we do not have to know the definition of the object. Kind of along the line of this:


Outside of the COM object, we have a C++ class:
class Foo
{
    // methods, variables, etc.
}

In the .idl file for the COM object, we have this:
[id(1), helpstring("method Test")] HRESULT Test( blah );

Is there a way to pass an instance of class Foo into the COM object through the interface method Test, with the ability to use the methods and variables within the Foo object from the COM object?

What would the parameters in the instance method be?
0
Comment
Question by:Kerplunk
6 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
include the class in the COM project
pass the Foo's pointer as unsigned long ie define method Test with parameter ulong
from the client pass the class pointer by casting it into ulong.

One thing u should take care is that,
if the class contains any read write operation, or any other synch needed operation, u should have to handle this...

GOOD LUCK
0
 

Author Comment

by:Kerplunk
Comment Utility
But what if we don't have the header file or any other file for the class, so we don't know what the definition is?

In Java I know we can use the Object class, since every new class is derived from it. Is there an equivalent in COM, so we can use a class without having to know what its structure is before hand?
0
 

Expert Comment

by:boneTKE
Comment Utility
In COM, all interfaces must derive from the IUnknown interface, and implement the 3 methods within that interface; QueryInterface, AddRef, and Release.  I don't know Java, but your statement about the Object class seems to parallel COM in this respect.

roshmon's suggestion is similar to using a void* in C/C++.  You can use a void* to hold onto any object, but if you want to access that object, eventually you'll have to cast it to the appropriate type (class).  This means you'll need the type definition.  Can't do much (reliably) without it.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 11

Expert Comment

by:griessh
Comment Utility
Dear Kerplunk

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to split between

     "roshmon and boneTKE"


If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 

Author Comment

by:Kerplunk
Comment Utility
I didn't forget about the question, I've just been trying to figure out how to solve it.

roshmon and boneTKE did answer one part of the question (sending an object into COM). However, after some reading, I found what I was looking for for the second part (using methods without the definitions). What I am looking for is called reflection (or introspection). This is where a class knows about its methods and variables, and can be seen in the Java reflection API (and the new .NET platform) because they both go off of a single root class (Object). It would seem that, to get this functionality in C++, a new class or interface would need to be created to simulate these effects, and used by classes outside of my project that are to be passed to the COM object.
0
 
LVL 6

Accepted Solution

by:
Mindphaser earned 0 total points
Comment Utility
refund of points and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

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…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

771 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

9 Experts available now in Live!

Get 1:1 Help Now