ATL and Base Class Pointers in COM 
Author Message
 ATL and Base Class Pointers in COM

Hii Group,

I would like to create 2 DLLs. The first DLL will export a handful of Random Number
Generators. The second DLL will allow a client to use the RNG.

I'm having problems with getting the sematics correct in the RNG DLL, so that the
second DLL can take an interface to the 'base class' DLL as an argument.

Here's what I want:
Base Class: PRNG (and interface IPRNG)
Derived: X917C, BBS, LCG, Sequence (and interface IX917C, etc)

In the second DLL, I would like a method such as:
SetRNG( IPRNG* newRNG );

Does anyone have sample code posted? I have not been able to get past a clean compile
on the RNG DLL. I think the problem is with my philosophy - and hence my
implementation. Pure virtuals in the PRNG ATL class cause COM errors. The ATL PRNG
base class in the first DLL compiles OK (but does nothing). When I try to derive from
it (for example, a simple Sequence), a lot of things break. This is after commenting
out a lot of the derived ATL code.

I've looked through a few of my books (Curland's VB book, Box's essential COM), but
neither really talk about - or I have not found a discussion of it. Google has not
lead me to anything useful either (but I probably have not found the proper key words
at this point).

Thanks in advance,
Jeff



Thu, 15 Sep 2005 16:26:00 GMT  
 ATL and Base Class Pointers in COM
It sounds like you are caught up trying to set up one COM implementation to
inherit from another. There is no reason to do this. Why not simply develop
two independent COM objects, where one simply happens to call the other when
one of its methods or properties is called?

If you are trying to use one COM object to expose externally an interface
that is implemented by an internally instantiated COM object, then the
technique for doing this is called "aggregation". That's the key word to
look for when searching MSDN, or any good COM book. However, I just don't
think you need it in the circumstances you describe.

HTH

Brian



Fri, 16 Sep 2005 07:17:04 GMT  
 ATL and Base Class Pointers in COM

Quote:

> I would like to create 2 DLLs. The first DLL will export a handful of Random Number
> Generators. The second DLL will allow a client to use the RNG.

> I'm having problems with getting the sematics correct in the RNG DLL, so that the
> second DLL can take an interface to the 'base class' DLL as an argument.

> Here's what I want:
> Base Class: PRNG (and interface IPRNG)
> Derived: X917C, BBS, LCG, Sequence (and interface IX917C, etc)

> In the second DLL, I would like a method such as:
> SetRNG( IPRNG* newRNG );

> Does anyone have sample code posted? I have not been able to get past a clean compile
> on the RNG DLL. I think the problem is with my philosophy - and hence my
> implementation. Pure virtuals in the PRNG ATL class cause COM errors. The ATL PRNG
> base class in the first DLL compiles OK (but does nothing). When I try to derive from
> it (for example, a simple Sequence), a lot of things break. This is after commenting
> out a lot of the derived ATL code.

> I've looked through a few of my books (Curland's VB book, Box's essential COM), but
> neither really talk about - or I have not found a discussion of it. Google has not
> lead me to anything useful either (but I probably have not found the proper key words
> at this point).

It sounds like these might help:
http://www.mvps.org/vcfaq/com/7.htm
http://www.mvps.org/vcfaq/com/8.htm

There's nothing inherently wrong with what you're doing.  As long as
you cross all the t's and dot all the i's, it looks to me like it
should work.  The only thing that I see that looks like it might not
be right is providing an implementation for PRNG - it looks to me
like that should probably just be an interface that's implemented
by the separate generator coclasses.

--
Craig Powers
MVP - Visual C++



Fri, 16 Sep 2005 22:55:06 GMT  
 ATL and Base Class Pointers in COM


| >
| > I would like to create 2 DLLs. The first DLL will export a handful of Random
Number
| > Generators. The second DLL will allow a client to use the RNG.
| >
| > I'm having problems with getting the sematics correct in the RNG DLL, so that the
| > second DLL can take an interface to the 'base class' DLL as an argument.
| >
| > Here's what I want:
| > Base Class: PRNG (and interface IPRNG)
| > Derived: X917C, BBS, LCG, Sequence (and interface IX917C, etc)
| >
| > In the second DLL, I would like a method such as:
| > SetRNG( IPRNG* newRNG );
| >
| > Does anyone have sample code posted? I have not been able to get past a clean
compile
| > on the RNG DLL. I think the problem is with my philosophy - and hence my
| > implementation. Pure virtuals in the PRNG ATL class cause COM errors. The ATL PRNG
| > base class in the first DLL compiles OK (but does nothing). When I try to derive
from
| > it (for example, a simple Sequence), a lot of things break. This is after
commenting
| > out a lot of the derived ATL code.
| >
| > I've looked through a few of my books (Curland's VB book, Box's essential COM),
but
| > neither really talk about - or I have not found a discussion of it. Google has not
| > lead me to anything useful either (but I probably have not found the proper key
words
| > at this point).
|
| It sounds like these might help:
| http://www.mvps.org/vcfaq/com/7.htm
| http://www.mvps.org/vcfaq/com/8.htm
|
| There's nothing inherently wrong with what you're doing.  As long as
| you cross all the t's and dot all the i's, it looks to me like it
| should work.  The only thing that I see that looks like it might not
| be right is providing an implementation for PRNG - it looks to me
| like that should probably just be an interface that's implemented
| by the separate generator coclasses.
|
| --
| Craig Powers
| MVP - Visual C++

Hi Craig,

Its good to hear from you again (its actually good to hear from anyone who knows more
than I do).

I'm using aggregation as Brian pointed out. I'm using a IPRNG coclass as you
suggested.
The implementation feels like beating a square peg into a round hole.  I can't get a 1
to 1 correspondence of VC++ to COM ATL. Its very awkward.

I'm sorry to give so many details. I know I don't want to read a lot of noise. But in
this context, I think it makes a lot of sense (its a good example) - as does everyone
else!

Jeff



Sat, 17 Sep 2005 13:59:18 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. ATL COM - Passing ATL COM classes through another ATL COM class in the same app

2. Connection points between a VB COM-based and ATL COM-based (NT Service) MTA

3. Is there a way for communication between instances of an ATL based com class

4. Is there a way for communication between instances of an ATL based com class

5. how to convert base class pointer to sub class pointer

6. Newbie Q: Using a pointer to a COM class with in the ATL project

7. COM/ATL novice:passing object pointers through methods on a COM interface

8. passing COM object pointers to another COM object in ATL

9. Inherited class function calls from a pointer assigned to the base class

10. Howto Expose a normal C++ class with methods via an Interface Class in ATL COM

11. ATL COM Class Final Construct dies with Member Accessor Class

12. Registering ATL-based COM .dll

 

 
Powered by phpBB® Forum Software