Solved

COM interfaces appearence in VB Client

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

687 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