HighTechTalks DotNet Forums  

exposing .net methods through interfaces?

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss exposing .net methods through interfaces? in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Andrew Brook
 
Posts: n/a

Default exposing .net methods through interfaces? - 11-01-2007 , 10:40 AM






Hi Everyone,

I have a .NET 2.0 set of classes that i've recently attempted to call from
an MFC application using regasm to generate and register a type library. I
didn't author my classes with the intention that they would be called from
an unmanaged application and i've run into a few problems.

Let's say for example that i have a Class A. I could see this class in the
MFC app, but i couldn't see any of it's public methods or properties. It
wasn't until I made Class A implement Interface A that I could see the
methods using the interface and the following code

IClassA clsA(__uuidof(ClassA));

But what if I want Class A to inherit from two interfaces. If I can indeed
only access my methods using the interface, do I have to create two
variables, one for each interface?

I'm seriously hoping i've got something wrong along the way

thanks,
Andrew



Reply With Quote
  #2  
Old   
Foz
 
Posts: n/a

Default RE: exposing .net methods through interfaces? - 11-02-2007 , 09:57 AM






Hi Andrew,

If an object exposes multiple interfaces, you need a separate interface
variable to access each one. This allows clients to program to an interface
rather than implementation and affords decoupling. This is good practice in
general, so that when someday you need to replace ClassA with SomeOtherAClass
your clients only need to update the CoClass.

"Andrew Brook" wrote:

Quote:
Hi Everyone,

I have a .NET 2.0 set of classes that i've recently attempted to call from
an MFC application using regasm to generate and register a type library. I
didn't author my classes with the intention that they would be called from
an unmanaged application and i've run into a few problems.

Let's say for example that i have a Class A. I could see this class in the
MFC app, but i couldn't see any of it's public methods or properties. It
wasn't until I made Class A implement Interface A that I could see the
methods using the interface and the following code

IClassA clsA(__uuidof(ClassA));

But what if I want Class A to inherit from two interfaces. If I can indeed
only access my methods using the interface, do I have to create two
variables, one for each interface?

I'm seriously hoping i've got something wrong along the way

thanks,
Andrew




Reply With Quote
  #3  
Old   
Andrew Brook
 
Posts: n/a

Default Re: exposing .net methods through interfaces? - 11-08-2007 , 10:15 AM



Thanks for your response,

I guess this just means I need to design my classes a little better with
this in mind, good job i'm still at the design stage of this!

thanks again,
Andrew

"Foz" <Foz (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi Andrew,

If an object exposes multiple interfaces, you need a separate interface
variable to access each one. This allows clients to program to an
interface
rather than implementation and affords decoupling. This is good practice
in
general, so that when someday you need to replace ClassA with
SomeOtherAClass
your clients only need to update the CoClass.

"Andrew Brook" wrote:

Hi Everyone,

I have a .NET 2.0 set of classes that i've recently attempted to call
from
an MFC application using regasm to generate and register a type library.
I
didn't author my classes with the intention that they would be called
from
an unmanaged application and i've run into a few problems.

Let's say for example that i have a Class A. I could see this class in
the
MFC app, but i couldn't see any of it's public methods or properties. It
wasn't until I made Class A implement Interface A that I could see the
methods using the interface and the following code

IClassA clsA(__uuidof(ClassA));

But what if I want Class A to inherit from two interfaces. If I can
indeed
only access my methods using the interface, do I have to create two
variables, one for each interface?

I'm seriously hoping i've got something wrong along the way

thanks,
Andrew






Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.