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 2007

Tip: Looking for answers? Try searching our database.

Using an MC++ abstract base class in C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Spahn - 21 Jun 2007 15:54 GMT
I have an abstract base class defined in an MC++ class library.  I then
create a descendent class in a C# class library.  This seems to work OK with
the exception of one of the abstract member functions/pure virtual function
that uses a passed in pointer to a long.  

Just using pointers in the C# library results in the expected:  Pointers and
fixed size buffers may only be used in an unsafe context.  And using the
'ref' keyword doesn't provide the correct function: no suitable method found
to override.

Any help would be greatly appreciated.

Thanks.
Bill
Tamas Demjen - 21 Jun 2007 17:49 GMT
> Just using pointers in the C# library results in the expected:  Pointers and
> fixed size buffers may only be used in an unsafe context.

Take a look at IntPtr. It was designed to store unmanaged pointers and
handles in a managed environment, even with languages that can't handle
pointer syntax at all.

http://msdn2.microsoft.com/en-us/library/system.intptr.aspx

You can use IntPtr to store a pointer's value, but if you actually want
to dereference that pointer, that automatically makes your assembly
unsafe. In C#, you can only use pointer syntax in unsafe context.

Tom
tivofan - 21 Jun 2007 18:08 GMT
My descendent class overrides an abstract function that needs to modify a
32bit int within the function.  In C#, I would just pass in the value as ref
or out.  In MC++ I would just pass in a pointer.  But since the abstract
class is defined in an MC++ class library and the descenedent class is
defined in a C# class library, I am having a problem finding a parameter
declaration that works for both.

> > Just using pointers in the C# library results in the expected:  Pointers and
> > fixed size buffers may only be used in an unsafe context.
[quoted text clipped - 10 lines]
>
> Tom
Tamas Demjen - 21 Jun 2007 18:26 GMT
> My descendent class overrides an abstract function that needs to modify a
> 32bit int within the function.  In C#, I would just pass in the value as ref
> or out.  In MC++ I would just pass in a pointer.  But since the abstract
> class is defined in an MC++ class library and the descenedent class is
> defined in a C# class library, I am having a problem finding a parameter
> declaration that works for both.

If you are talking about the old VS 2003 Managed C++ syntax, here's how
to do it:
http://www.thescripts.com/forum/thread281243.html

In VS 2005 (C++/CLI), there is such a thing as a managed reference:
http://tinyurl.com/3axp9r

Either way, C++ provides a syntax that's compatible with ref and out
parameters in C#.

Tom
tivofan - 21 Jun 2007 18:58 GMT
OK, I see now that I needed to use a tracking reference '%' instead of the
pointer reference.  

Thanks very much for your help.

Bill

> > My descendent class overrides an abstract function that needs to modify a
> > 32bit int within the function.  In C#, I would just pass in the value as ref
[quoted text clipped - 14 lines]
>
> Tom

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.