Solved

COM interfaces appearence in VB Client

Posted on 2003-10-26
1
206 Views
Last Modified: 2010-04-01
Hi,
I have a VC++ COM server application and a VB client that uses the server.
Some of the interfaces are not shown as I expected in the VB application (it seems like the appearence of them
depends on the order that they are written in the idl file).
for example, if I have the following declaration (in the idl):
      [
            uuid(1960D896-6ED7-483B-8C73-35C913DA9657),
            helpstring("Book Class")
      ]
      coclass Book
      {
            interface IBook;
            interface IBall;
            interface IPool;
      };
then if I try to create in the VB an object of type Book, the list that contains all the interfaces/objects does not contain "IBook",
it contains: "Book", "IBall" , "IPool".
I noticed also that every interface that is define first in the coclass declaration will not be shown in the VB.

Does someone know about a macro/flag that I can add inorder that the VB will show all the interfaces ???

thanks,
Yoav.

0
Comment
Question by:yoavo
1 Comment
 
LVL 9

Accepted Solution

by:
_ys_ earned 70 total points
ID: 9625947
Your coclass declaration is equivalent to this:
[
    uuid(1960D896-6ED7-483B-8C73-35C913DA9657),
    helpstring("Book Class")
]
coclass Book
{
    [default] interface IBook;
    interface IBall;
    interface IPool;
};

Notice the default attribute. In VB code when you code as such:

Dim bkBook As Book
Set bkBook = New Book

What is actually happening is VB is declaring the type as whatever [default] was.

Dim bkBook As IBook
Set bkBook = New Book

As you already know, it also hides whatever the [default] is.

You *can* however still declare a variable as IBook, and I would encourage you to do so. If [default] ever changes, at least your code won't break.

>> Does someone know about a macro/flag that I can add inorder that the VB will show all the interfaces ???
Unfortunately there isn't one. *But* what you can do, and it's quite a kludge, is inherit all your interfaces from an empty base interface, and declare this as [default].

[
    uuid(1960D896-6ED7-483B-8C73-35C913DA9657),
    helpstring("Book Class")
]
coclass Book
{
    [default] interface IVbNamed;
    interface IBook;
    interface IBall;
    interface IPool;
};

[IVbNamed will reveal itself to most other COM clients - which is not good]

If you remeber that 'Dim bkBook As Book' is equivalent to 'Dim bkBook As IBook', and always declare it as such, as recommended, you can do away with the above kludge
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now