?
Solved

Objects in COM

Posted on 2002-03-25
6
Medium Priority
?
212 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
[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
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

719 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