Convert variant to object (VB-COM used in VC) 
Author Message
 Convert variant to object (VB-COM used in VC)

Hi,

In a VC program I use a COM-object build in Visual Basic. There's a function
in this COM-object, that returns an object.
In VB the call of this function is easy and locks like this:

Dim MyObj
Set MyObj = MyEtmObj.GetObject("ObjName")

in VC the function has the automatically generated Header:

VARIANT GetObject(BSTR* modname);

How can I convert a variant to an object? Is there a way like
variantVariable.intVal for integers?

Michael



Sun, 21 Sep 2003 14:00:45 GMT  
 Convert variant to object (VB-COM used in VC)
you get the objects IDispatch* interface through
variantVariable.pdispVal

then you can use that to QI for a custom interface
(if one is implemented by the object)

/johan


Quote:
> Hi,

> In a VC program I use a COM-object build in visual basic. There's a
function
> in this COM-object, that returns an object.
> In VB the call of this function is easy and locks like this:

> Dim MyObj
> Set MyObj = MyEtmObj.GetObject("ObjName")

> in VC the function has the automatically generated Header:

> VARIANT GetObject(BSTR* modname);

> How can I convert a variant to an object? Is there a way like
> variantVariable.intVal for integers?

> Michael



Sun, 21 Sep 2003 15:25:20 GMT  
 Convert variant to object (VB-COM used in VC)

Quote:
>Dim MyObj
>Set MyObj = MyEtmObj.GetObject("ObjName")

>in VC the function has the automatically generated Header:

>VARIANT GetObject(BSTR* modname);

>How can I convert a variant to an object? Is there a way like
>variantVariable.intVal for integers?

Michael,

A VARIANT is a union of several possible types (see "VARIANT and
VARIANTARG" in the Platform SDK docs).

There are functions (such as VariantChangeType) to convert a VARIANT
to different forms, but in your situation, I guess your VARIANT will
be an IDispatch pointer (the vt member == VT_DISPATCH - the pdispVal
value of the VARIANT).

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Sun, 21 Sep 2003 15:36:21 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problem with scripting context when using VB com object inside VC com object

2. Testing a Variant Output argument in ATL Com object using VB client

3. passing objects from VB as VARIANT to COM server object failing

4. passing objects from VB as VARIANT to COM server object failing

5. creating a sink in VC to handle events fired by VB Com Object

6. Using apartment-threaded VB COM objects from multithread

7. Problem using a VB COM object in ATL project

8. Using a VB Com object in a VC++ Program

9. Using COM objects within COM objects

10. Using VC++ COM Objects in VB

11. Need help to start using a COM object in VC app

12. using COM object in VC++6

 

 
Powered by phpBB® Forum Software