Solved

COM interfaces appearence in VB Client

Posted on 2003-10-26
1
207 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

910 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