Hi everybody.
I'm writing a .NET wrapper class for a native C++ library and decided
to do it in C++/CLI. One of the problems I ran in to is the following.
In C++ I have the following
public ref class MyClass
{
...
bool DoIt(DateTime^% date);
bool DoIt2([OutAttribute] DateTime^% date)
}
which I think should translate into a method calls with c# syntax:
bool DoIt(ref DateTime date);
bool DoIt2(out DateTime date);
So I was a bit puzzled when the following showed up:
bool DoIt(ref ValueType date);
Where is my type safety? What am I doing wrong? Am I trying to do
something (returning value types from c++/cli via ref and out) that is
just not possible?
bool DoIt(ref ValueType date);
Ben Voigt [C++ MVP] - 25 Sep 2007 22:24 GMT
> Hi everybody.
>
[quoted text clipped - 22 lines]
> something (returning value types from c++/cli via ref and out) that is
> just not possible?
You're using tracking handles (^) with a value type, which is not needed or
desired.
Just "bool DoIt(DateTime% date);" will work properly.
> bool DoIt(ref ValueType date);
soren.enemaerke@gmail.com - 26 Sep 2007 08:20 GMT
> <soren.enemae...@gmail.com> wrote in message
>
[quoted text clipped - 37 lines]
>
> - Vis tekst i anf?rselstegn -
Thanks Ben, worked like a charm.
Sheng Jiang[MVP] - 26 Sep 2007 20:00 GMT
DateTime is a value type, however the track handle ^ makes the parameter to
be boxed. C# does not understand the type of a boxed value type, but C++/CLI
does. So you have ref ValueType in C#, and DateTime^ in C++/CLI.

Signature
Sheng Jiang
Microsoft MVP in VC++
> Hi everybody.
>
[quoted text clipped - 24 lines]
>
> bool DoIt(ref ValueType date);