Solved

Objects in COM

Posted on 2002-03-25
6
199 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
ID: 6895870
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
ID: 6896907
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
ID: 6898274
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 11

Expert Comment

by:griessh
ID: 6956138
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
ID: 6960455
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
ID: 7010024
refund of points and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GUI: DIalog Stacking and Popping in MS C++ 4 80
Post a good COM tutorial 1 60
Recommendation vb6 to vb.net or others 14 174
FMX TEdit KeyUp handler detecting  "enter" key 4 13
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

809 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