Solved

Objects in COM

Posted on 2002-03-25
6
208 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
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.

630 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