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 / .NET Framework / Interop / January 2007

Tip: Looking for answers? Try searching our database.

Access protected members of a class from another class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bumbala - 11 Jan 2007 15:09 GMT
Hello,

I am working on a Windows Forms Control Library project which has some
unmanaged code in it. This library will be used in C# Windows
Application. Some of the managed classes have protected unmanaged class
members. They must be reached by other classes inside the Library, but
not outside. In old times, I would achieve this by:

class A
{
 // managed code does not support this?
 friend class B;

protected:
 CUnmanagedClass *pProtectedMember;
  void ProtectedMethodOfA() {}

public:
 void PublicMethodOfA() {}
}

class B
{
public:
 void DoSomeWork()
 {
   // I could reach protected members and methods of A in old times...
   InstanceOfA->pProtectedMember->DoSomething();
   InstanceOfA->ProtectedMethodOfA();
 }
}

How can I do it in managed code?

Thank you!
Christian Fröschlin - 11 Jan 2007 15:27 GMT
> I am working on a Windows Forms Control Library project which has some
> unmanaged code in it. This library will be used in C# Windows
> Application. Some of the managed classes have protected unmanaged class
> members. They must be reached by other classes inside the Library, but
> not outside.

There is an 'internal' access modifier in C#, but I don't know how to
specify this in managed C++. Also note that 'protected internal' will
again make the member visible to derived types outside the library.
Bumbala - 11 Jan 2007 15:37 GMT
internal worked! Thanks a lot!

Christian Fr?schlin wrote:

> > I am working on a Windows Forms Control Library project which has some
> > unmanaged code in it. This library will be used in C# Windows
[quoted text clipped - 5 lines]
> specify this in managed C++. Also note that 'protected internal' will
> again make the member visible to derived types outside the library.

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.