Using an MC++ abstract base class in C#

G

Guest

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
 
T

Tamas Demjen

Bill said:
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
 
G

Guest

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.
 
T

Tamas Demjen

tivofan said:
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
 
G

Guest

OK, I see now that I needed to use a tracking reference '%' instead of the
pointer reference.

Thanks very much for your help.

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top