Board index » cppbuilder » Multiple COM Objects implementing 1 Interface

Multiple COM Objects implementing 1 Interface

Hi,

I'm using BCB4 and I'm quite new to COM.  Just wanting to ask the
question: how do I create multiple COM objects (DLLs) implementing the
same interface?

I can easily create an interface and the initial CoClass:
   --> new ActiveX Library
   --> new Automation Object

Once the interface is defined and the 1st CoClass is implemented, I have
trouble creating additional CoClass implementations.  From the Type
Library Viewer, I click on CoClass and fill in the details etc, and the
new CoClass appears in the tree.  However, no implementation files (eg.
MySecondObjImpl.cpp/h) are created.

I realise that there is a way to do this manually - ie copy and rename
the 1st COM OBJs implementation files and change all GUID references to
the 1st COM obj over to the new one, and change the actual CoClass name.
  I figure though, that there must be another easier way of doing this,
ie using some feature of the IDE.

I tried creating a new 'COM Object', hoping then to be able to implement
the interface that I'd created earlier, but this wizard forcefully
creates a new interface based on the name of the new COM Object.

So is there any other way to go about creating multiple COM Objects
implementing the same interface easily, through the IDE?

Any help is greatly appreciated.  Thanks very much in advance for your help.

Prem.

 

Re:Multiple COM Objects implementing 1 Interface


Are you inserting the existing interface using the type library editor and
selecting refresh ?

That *should* work.

Phil.

Re:Multiple COM Objects implementing 1 Interface


Hi Phil,

Thanks for your reply.

I tried that, however, the implementation files for the CoClass aren't
generated automatically.  It appears to modify the type library
appropriately, generating a GUID etc.  But still no implementation files!

Appreciate your suggestion.

Prem.

Quote
Phil Parker wrote:
> Are you inserting the existing interface using the type library editor and
> selecting refresh ?

> That *should* work.

> Phil.

Re:Multiple COM Objects implementing 1 Interface


No, you have to create the impl files for all additional interfaces you add
to the CoClass.

BigStew

Quote
"Prem" <prem_removefors...@hotmail.com> wrote in message

news:3D2A484D.5080202@hotmail.com...
Quote
> I realise that there is a way to do this manually - ie copy and rename
> the 1st COM OBJs implementation files and change all GUID references to
> the 1st COM obj over to the new one, and change the actual CoClass name.
>   I figure though, that there must be another easier way of doing this,
> ie using some feature of the IDE.

Re:Multiple COM Objects implementing 1 Interface


Now when I did this recently, I created a new type library and COM control
and
copy / pasted my previous interface definition through the "text" contents.
I didn't
let the new COM control pick its own CoClass name - I typed in the correct
name instead.

This may not be the "right way" to do it, but I didn't take time to ask -
maybe someone
out there can give a better/faster/more correct way to accomplish this?

Curt

Quote
"Phil Parker" <ppar...@adelphia.net> wrote in message

news:3d2a66b2$1_2@dnews...
Quote
> Are you inserting the existing interface using the type library editor and
> selecting refresh ?

> That *should* work.

> Phil.

Re:Multiple COM Objects implementing 1 Interface


Ahhh, I see what you've probably been doing --

In order to create another COM object, do *NOT* select the new CoClass
button from the type library editor - this creates a CoClass in the type
library but does not add a COM object to your project.  Therefore you won't
get a .cpp and .h file generated.

Instead, using the new COM object or new automation object wizard --
Select File -> New -> ActiveX -> COM Object (or Automation Object).

There are a few annoying things with BCB on this - it doesn't allow you to
select the existing defined interface from the current type library and
forces you to create a new interface.  However, after having created the COM
object, you can remove the existing interface from the list of interfaces
implemented by your component (using the tlb editor) and you can then add
the interface you want to implement -- to do this select the coclass in the
tlb editor, select the implements tab and right click and select 'insert
interface' and select the interface you want to implement.  To remove an
unused interface select it in the implements tab and press delete.  You can
then also delete the actual interface definition using the tlb editor.

Phil.

Quote
"Prem" <prem_removefors...@hotmail.com> wrote in message

news:3D2A695E.1020202@hotmail.com...
Quote
> Hi Phil,

> Thanks for your reply.

> I tried that, however, the implementation files for the CoClass aren't
> generated automatically.  It appears to modify the type library
> appropriately, generating a GUID etc.  But still no implementation files!

> Appreciate your suggestion.

> Prem.

Re:Multiple COM Objects implementing 1 Interface


See my previous reply -- you don't have to do this.

Quote
"Big Stew" <Big_S...@talk21.com> wrote in message news:3d2a9a9c_2@dnews...
> No, you have to create the impl files for all additional interfaces you
add
> to the CoClass.

> BigStew

> "Prem" <prem_removefors...@hotmail.com> wrote in message
> news:3D2A484D.5080202@hotmail.com...
> > I realise that there is a way to do this manually - ie copy and rename
> > the 1st COM OBJs implementation files and change all GUID references to
> > the 1st COM obj over to the new one, and change the actual CoClass name.
> >   I figure though, that there must be another easier way of doing this,
> > ie using some feature of the IDE.

Re:Multiple COM Objects implementing 1 Interface


When you do this, you are *not* implementing the same interface, you are
implementing two interfaces which happen to have the same methods.

If you require polymorphic behavior this will not achieve what you want.
See my previous reply to Prem -- there are some details there for how to use
the wizards to implement the same interface on two or more components.

Note also, you can implement existing interfaces from seperate type library
files by adding type libraries to the 'uses' list.

Quote
"Curt Peterson" <c...@strikeforcesoftware.com> wrote in message

news:3d2aed19$1_2@dnews...
Quote
> Now when I did this recently, I created a new type library and COM control
> and
> copy / pasted my previous interface definition through the "text"
contents.
> I didn't
> let the new COM control pick its own CoClass name - I typed in the correct
> name instead.

> This may not be the "right way" to do it, but I didn't take time to ask -
> maybe someone
> out there can give a better/faster/more correct way to accomplish this?

> Curt

> "Phil Parker" <ppar...@adelphia.net> wrote in message
> news:3d2a66b2$1_2@dnews...
> > Are you inserting the existing interface using the type library editor
and
> > selecting refresh ?

> > That *should* work.

> > Phil.

Re:Multiple COM Objects implementing 1 Interface


No, I actually replaced the text from the interface definition - GUID and
all -
I just thought maybe there was a way to grab it from the OCX and not doing
the cut-and-paste thing from the other TLB.

Curt

Quote
"Phil Parker" <par...@sensormatic.com> wrote in message

news:3d2af311$1_2@dnews...
Quote
> When you do this, you are *not* implementing the same interface, you are
> implementing two interfaces which happen to have the same methods.

> If you require polymorphic behavior this will not achieve what you want.
> See my previous reply to Prem -- there are some details there for how to
use
> the wizards to implement the same interface on two or more components.

> Note also, you can implement existing interfaces from seperate type
library
> files by adding type libraries to the 'uses' list.

> "Curt Peterson" <c...@strikeforcesoftware.com> wrote in message
> news:3d2aed19$1_2@dnews...
> > Now when I did this recently, I created a new type library and COM
control
> > and
> > copy / pasted my previous interface definition through the "text"
> contents.
> > I didn't
> > let the new COM control pick its own CoClass name - I typed in the
correct
> > name instead.

> > This may not be the "right way" to do it, but I didn't take time to
ask -
> > maybe someone
> > out there can give a better/faster/more correct way to accomplish this?

> > Curt

> > "Phil Parker" <ppar...@adelphia.net> wrote in message
> > news:3d2a66b2$1_2@dnews...
> > > Are you inserting the existing interface using the type library editor
> and
> > > selecting refresh ?

> > > That *should* work.

> > > Phil.

Re:Multiple COM Objects implementing 1 Interface


That's even worse, then.

Because now you have two definitions of the interface and they have to be
maintained independently.

A better way to do this is to:

1. Create ActiveX library with one implementation of the COM interface in
question.
2. Create second ActiveX library.
3. Add type library from first ActiveX library to second ActiveX library.
4. Create Com object in second ActiveX library, tell new COM object that it
is implementing the appropriate interface from the first ActiveX library.

You now have an object in the first library and in the second library that
both implement the same interface.

What I have done in some cases is define an interface that my ActiveX code
expects, for example a plug-in interface, with no implementation at all in
the first ActiveX library.

--
-- Early Ehlinger CEO, ResPower Inc - Toll-Free : 866-737-7697 --
- RenderFarm - Lightwave , 3dSMax , Bryce , Maya , AfterEffects -
--- www.respower.com -- 150 GHz Starting At USD$0.50/GHz*Hour ---
----------------- SuperComputing For the Masses! ----------------
"I'm so busy programming my computer to let me be lazy, I never
get any rest!" - John Kaster

Quote
"Curt Peterson" <c...@strikeforcesoftware.com> wrote in message

news:3d2b03bd$1_2@dnews...
Quote
> No, I actually replaced the text from the interface definition - GUID and
> all -
> I just thought maybe there was a way to grab it from the OCX and not doing
> the cut-and-paste thing from the other TLB.

> Curt

> "Phil Parker" <par...@sensormatic.com> wrote in message
> news:3d2af311$1_2@dnews...
> > When you do this, you are *not* implementing the same interface, you are
> > implementing two interfaces which happen to have the same methods.

> > If you require polymorphic behavior this will not achieve what you want.
> > See my previous reply to Prem -- there are some details there for how to
> use
> > the wizards to implement the same interface on two or more components.

> > Note also, you can implement existing interfaces from seperate type
> library
> > files by adding type libraries to the 'uses' list.

> > "Curt Peterson" <c...@strikeforcesoftware.com> wrote in message
> > news:3d2aed19$1_2@dnews...
> > > Now when I did this recently, I created a new type library and COM
> control
> > > and
> > > copy / pasted my previous interface definition through the "text"
> > contents.
> > > I didn't
> > > let the new COM control pick its own CoClass name - I typed in the
> correct
> > > name instead.

> > > This may not be the "right way" to do it, but I didn't take time to
> ask -
> > > maybe someone
> > > out there can give a better/faster/more correct way to accomplish
this?

> > > Curt

> > > "Phil Parker" <ppar...@adelphia.net> wrote in message
> > > news:3d2a66b2$1_2@dnews...
> > > > Are you inserting the existing interface using the type library
editor
> > and
> > > > selecting refresh ?

> > > > That *should* work.

> > > > Phil.

Re:Multiple COM Objects implementing 1 Interface


How do you do step 3? What do you mean here? I think this is the whole
issue.

There seems to be some confusion regarding the process of "importing" the
interface in question into the new type library. How is it _supposed_ to be
done?

Curt

Quote
"Early Ehlinger" <ear...@yahoo.com> wrote in message

news:3d2b37b3$1_1@dnews...
Quote
> That's even worse, then.

> Because now you have two definitions of the interface and they have to be
> maintained independently.

> A better way to do this is to:

> 1. Create ActiveX library with one implementation of the COM interface in
> question.
> 2. Create second ActiveX library.
> 3. Add type library from first ActiveX library to second ActiveX library.
> 4. Create Com object in second ActiveX library, tell new COM object that
it
> is implementing the appropriate interface from the first ActiveX library.

> You now have an object in the first library and in the second library that
> both implement the same interface.

> What I have done in some cases is define an interface that my ActiveX code
> expects, for example a plug-in interface, with no implementation at all in
> the first ActiveX library.

> --
> -- Early Ehlinger CEO, ResPower Inc - Toll-Free : 866-737-7697 --
> - RenderFarm - Lightwave , 3dSMax , Bryce , Maya , AfterEffects -
> --- www.respower.com -- 150 GHz Starting At USD$0.50/GHz*Hour ---
> ----------------- SuperComputing For the Masses! ----------------
> "I'm so busy programming my computer to let me be lazy, I never
> get any rest!" - John Kaster

> "Curt Peterson" <c...@strikeforcesoftware.com> wrote in message
> news:3d2b03bd$1_2@dnews...
> > No, I actually replaced the text from the interface definition - GUID
and
> > all -
> > I just thought maybe there was a way to grab it from the OCX and not
doing
> > the cut-and-paste thing from the other TLB.

> > Curt

> > "Phil Parker" <par...@sensormatic.com> wrote in message
> > news:3d2af311$1_2@dnews...
> > > When you do this, you are *not* implementing the same interface, you
are
> > > implementing two interfaces which happen to have the same methods.

> > > If you require polymorphic behavior this will not achieve what you
want.
> > > See my previous reply to Prem -- there are some details there for how
to
> > use
> > > the wizards to implement the same interface on two or more components.

> > > Note also, you can implement existing interfaces from seperate type
> > library
> > > files by adding type libraries to the 'uses' list.

> > > "Curt Peterson" <c...@strikeforcesoftware.com> wrote in message
> > > news:3d2aed19$1_2@dnews...
> > > > Now when I did this recently, I created a new type library and COM
> > control
> > > > and
> > > > copy / pasted my previous interface definition through the "text"
> > > contents.
> > > > I didn't
> > > > let the new COM control pick its own CoClass name - I typed in the
> > correct
> > > > name instead.

> > > > This may not be the "right way" to do it, but I didn't take time to
> > ask -
> > > > maybe someone
> > > > out there can give a better/faster/more correct way to accomplish
> this?

> > > > Curt

> > > > "Phil Parker" <ppar...@adelphia.net> wrote in message
> > > > news:3d2a66b2$1_2@dnews...
> > > > > Are you inserting the existing interface using the type library
> editor
> > > and
> > > > > selecting refresh ?

> > > > > That *should* work.

> > > > > Phil.

Re:Multiple COM Objects implementing 1 Interface


COOL!

Thanks for your suggestion Phil!  That works really well.

Do you find that you still have to modify one or two lines in the
implementation file after your suggested procedure?

After changing two (obvious) lines in the implementation files, it
worked beautifully!

So, correct me if I'm wrong, but the 'automation server' is the
resulting (in my case) DLL, and this contains all the relevant 'COM
Objects' that I've created?

Thanks for everyone's (Phil, Curt, Early, & Stew) suggestions - really
do appreciate all your help.

Prem.

Quote
Phil Parker wrote:
> Ahhh, I see what you've probably been doing --

> In order to create another COM object, do *NOT* select the new CoClass
> button from the type library editor - this creates a CoClass in the type
> library but does not add a COM object to your project.  Therefore you won't
> get a .cpp and .h file generated.

> Instead, using the new COM object or new automation object wizard --
> Select File -> New -> ActiveX -> COM Object (or Automation Object).

> There are a few annoying things with BCB on this - it doesn't allow you to
> select the existing defined interface from the current type library and
> forces you to create a new interface.  However, after having created the COM
> object, you can remove the existing interface from the list of interfaces
> implemented by your component (using the tlb editor) and you can then add
> the interface you want to implement -- to do this select the coclass in the
> tlb editor, select the implements tab and right click and select 'insert
> interface' and select the interface you want to implement.  To remove an
> unused interface select it in the implements tab and press delete.  You can
> then also delete the actual interface definition using the tlb editor.

> Phil.

> "Prem" <prem_removefors...@hotmail.com> wrote in message
> news:3D2A695E.1020202@hotmail.com...

>> Hi Phil,

>> Thanks for your reply.

>> I tried that, however, the implementation files for the CoClass aren't
>> generated automatically.  It appears to modify the type library
>> appropriately, generating a GUID etc.  But still no implementation files!

>> Appreciate your suggestion.

>> Prem.

Re:Multiple COM Objects implementing 1 Interface


In order to use data types and interface types defined in a secondary type
library file you need to add it to the 'uses' list for the type library
which is going to make references to these types (be it through an
inheritance, implementation or parameter relationship).

In order to do this:

Open your project
View the project's type library
On the tree make sure the topmost node is selected (the top node represents
the type library itself).
On the right pane, select the 'Uses' tab.
Now right button click inside the 'Uses' tab and select 'Show all type
libraries' from the drop down menu.

At this point all the registered type libraries will be selected.  You then
need to find the name of the type library file you need to reference
(hopefully you've given it a decent descriptive name otherwise it's going to
be difficult to find).  Once you have found it, check the check box next to
the type library you wish to add a reference to.

Once you have done this, the type library is now in your 'Uses' list and any
interface or data type defined in the secondary type library can now be used
in your project's type library.

Phil.

Re:Multiple COM Objects implementing 1 Interface


Exactly.  That's what I was refering to when I mentioned adding a reference
to an existing type library.

Phil.

Re:Multiple COM Objects implementing 1 Interface


Well, I try to do that and all I get is "Error Loading Type Library / DLL."

I think that is what started me down the wrong path in the first place (this reminds
me of where I was a couple of weeks ago when I tried to do the "uses" thing...)

Does that mean my Registry is hosed? I have a couple of failed attempts at trying
to do the "plugin" architecture. I have three DLLs that implement the same interface
that show up in the "uses" choices. Two good ones and one "bad" (error generating)
one. The "bad" one is the only one in the "list" when I go to create my COM object.

Ugh,

Curt

P.S. Thanks for your help. :-)

Quote
"Phil Parker" <ppar...@adelphia.net> wrote in message news:3d2b9962_2@dnews...
> Exactly.  That's what I was refering to when I mentioned adding a reference
> to an existing type library.

> Phil.

Go to page: [1] [2]

Other Threads