Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2004

Tip: Looking for answers? Try searching our database.

Hidden interface

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fox - 29 Jun 2004 14:53 GMT
Hi all,

I would like to ask you a question regarding inheritence in C#.

I have a class which inherits from COM object, but then I want to pass
this class to the function expecting interface which COM object is
inherited from, I can't do it.

See sample:

C++ ATL project with COM interface A and COM object AInst
interface A
{
// some methods
}

class AInst : public A
{
// some methods
}

In C# I would like to do:
class AInstCSharp : public AInst
{
}

class B
{
  public static void Do( A a )
  {
      //do something
  }
}

Now somewhere in C# code:
AInstCSharp a = new AInstCSharp();

//next line will not compile due to an error CS1502
B.Do( a );

It seems that original interface A can't be used and also in object
browser I can't see that class AInstCSharp is inherited from A.
Do you have any idea how I can use it?

Fox
"Gary Chang" - 30 Jun 2004 07:33 GMT
Hi Fox,

For a default ATL COM object which inherits the interface A, it's
definition would be like:
class ATL_NO_VTABLE CA :
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CA, &CLSID_A>,
    public IDispatchImpl<IA, &IID_IA, &LIBID_PINT23Lib>
{
..

and when I tested the following code in a C# program, it is compiled OK:
public class AInstCSharp : AClass  //the COM object CA
{
}

class B
{
   public static void Do( A a ){}
}
..
AInstCSharp a = new AInstCSharp();
B b = new B();
B.Do(a);

..

I think the class AInst in your code snippet may be not a valid COM object,
so you cannot see the interface A in object browser.

Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.