Accessing multiple Interfaces of late bound objects

F

F.R.

I 've a VBA-Project where i have to use late bound objects.
(Like Set ... = CreateObject("ii.uu")
The object is created fine with its default interface. But the object
implements other interfaces (inherited from IDispatch). How can i access
them?

Thanks
Frank
 
C

Cindy M.

Hi F.R.,
I 've a VBA-Project where i have to use late bound objects.
(Like Set ... = CreateObject("ii.uu")
The object is created fine with its default interface. But the object
implements other interfaces (inherited from IDispatch). How can i access
them?
I'm not sure I understand completely where you're coming from, but I think
you need to expose everything you want VBA to be able to work with as a
public property and public method.

If this "ii.uu" is something you're programming with, say, .NET the better
place to ask would probably be the dotnet.framework.interop newsgroup. And
you need to provide a lot more details on how the COMInterop interface has
been constructed and is being provided.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
F

F.R.

Hi Cindy,

thanks for your post.

First of all, my problem is not a .NET problem. It's just 'simple' COM.
The object i like to create with VBA is written in C++ with ATL by
myself. The interface definition of the object in IDL looks like this:

[
object,
uuid( 7CB51F73-3AEC-4894-809F-A7EACEC5BBE0 ),
dual,
helpstring( "IContainerManagement" ),
pointer_default( unique )
]
interface IContainerManagement : IDispatch
{
[id(1)]
HRESULT GetSomething( [out, retval] SomeCollection **pCollection );
}
[
object,
uuid(EB82B59A-AB43-4138-8BC2-531BAE1FB75A),
dual,
helpstring("IGroupManagement"),
pointer_default(unique)
]
interface IGroupManagement : IDispatch
{
[id(1), helpstring("InsertGroup")]
HRESULT InsertGroup([in] const BSTR xmlDesc);
}

[
uuid(08899F12-5C59-42C1-B2AD-E51EBD4305AB),
helpstring("TheObject Class")
]
coclass TheObject
{
[default] interface IContainerManagement;
[] interface IGroupManagement;
}

So there are 2 interfaces in one object. It is no problem to access
the second interface if I use early binding, which is possible in all
office components.
Unlucky i have to use the object with another sw which is programmable
via VBA but does not support early binding. So I have to create all
objects via "CreateObject( "AppName.TheObject.1" )". The object I create
this way does only expose the [default] interface (IContainerManagement)
of the coclass TheObject. I'm looking for a way to access the
(IGroupManagement) of TheObject without rewriting the interfaces (if
possible).

Frank Recknagel
Software Service John, Germany
http://www.john-software.de
 
C

Cindy M.

Hi Frank,

No idea, sorry. I think you'll have better luck getting an answer to this
in a C++ newsgroup than a VBA newsgroup...
First of all, my problem is not a .NET problem. It's just 'simple' COM.
The object i like to create with VBA is written in C++ with ATL by
myself. The interface definition of the object in IDL looks like this:

[
object,
uuid( 7CB51F73-3AEC-4894-809F-A7EACEC5BBE0 ),
dual,
helpstring( "IContainerManagement" ),
pointer_default( unique )
]
interface IContainerManagement : IDispatch
{
[id(1)]
HRESULT GetSomething( [out, retval] SomeCollection **pCollection );
}
[
object,
uuid(EB82B59A-AB43-4138-8BC2-531BAE1FB75A),
dual,
helpstring("IGroupManagement"),
pointer_default(unique)
]
interface IGroupManagement : IDispatch
{
[id(1), helpstring("InsertGroup")]
HRESULT InsertGroup([in] const BSTR xmlDesc);
}

[
uuid(08899F12-5C59-42C1-B2AD-E51EBD4305AB),
helpstring("TheObject Class")
]
coclass TheObject
{
[default] interface IContainerManagement;
[] interface IGroupManagement;
}

So there are 2 interfaces in one object. It is no problem to access
the second interface if I use early binding, which is possible in all
office components.
Unlucky i have to use the object with another sw which is programmable
via VBA but does not support early binding. So I have to create all
objects via "CreateObject( "AppName.TheObject.1" )". The object I create
this way does only expose the [default] interface (IContainerManagement)
of the coclass TheObject. I'm looking for a way to access the
(IGroupManagement) of TheObject without rewriting the interfaces (if
possible).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
F

F.R.

Cindy said:
Hi Frank,

No idea, sorry. I think you'll have better luck getting an answer to this
in a C++ newsgroup than a VBA newsgroup...

I dont think so. Dont know C++ programmers with VBA knowledge. ;-)
 
C

Cindy M.

Hi F.R.,
Dont know C++ programmers with VBA knowledge. ;-)
I don't believe this is strictly a VBA question. It's more
along interop lines of C++ with classic Visual Basic (the
full thing, not VBA). If you can find out how to do it with
VB, that should translate to VBA. Classic VB developers
have, in general, a better grasp and more experience with
this level of programming technique :)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
K

Karl E. Peterson

F.R. said:
I 've a VBA-Project where i have to use late bound objects.
(Like Set ... = CreateObject("ii.uu")
The object is created fine with its default interface. But the object
implements other interfaces (inherited from IDispatch). How can i
access them?

Say object CFoo implements interface IBar, you'd do:

Dim f As Object 'CFoo
Dim b As IBar
Set f = CreateObject("<class.server>")
Set b = f

If I understand the question, at any rate.
 
F

F.R.

Karl said:
Say object CFoo implements interface IBar, you'd do:

Dim f As Object 'CFoo
Dim b As IBar
Set f = CreateObject("<class.server>")
Set b = f

If I understand the question, at any rate.

So you project knows the interface IBar, which can only be achieved by
inserting a reference to the object. This is early binding. With late
binding you have to write:

Dim f As Object 'CFoo
Dim b As Object
Set f = CreateObject("<class.server>")
Set b = f

Now b is exactly f with the default interface of f.

Even with additional functionality of the CFoo class, which returns
pointers to the other interfaces like

Dim f As Object 'CFoo
Dim b As Object
Set f = CreateObject("<class.server>")
Set b = f.GetSecondInterface()

b will be f with its default interface, except you return an new object
with the second interface as the default. (Which i didnt want to.)
 
F

F.R.

Cindy said:
Hi F.R.,
I don't believe this is strictly a VBA question. It's more
along interop lines of C++ with classic Visual Basic (the
full thing, not VBA). If you can find out how to do it with
VB, that should translate to VBA. Classic VB developers
have, in general, a better grasp and more experience with
this level of programming technique :)

Hi Cindy!

You're right, its not strictly VBA, it happens with late bound objects
in any VB environment. May be I should really try in a VB group. But so
far I now at this time solving this is just not possible. We have
convinced our customer to implement an VBA environment with early
binding. This will really solve my problem ;-).

Thanks!
Frank
 
K

Karl E. Peterson

F.R. said:
So you project knows the interface IBar, which can only be achieved by
inserting a reference to the object.

Yeah, you're right. I didn't fully understand the question. If you aren't allowed
any previous knowledge of the interface you're after, the best I can recommend is
you hunt up a copy of "Advanced Visual Basic 6" by Matt Curland. I suspect that if
anyone's cracked this one, it'd be him.

http://www.powervb.com/

Sorry... Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top