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++ / September 2007

Tip: Looking for answers? Try searching our database.

C++/CLI DateTime method argument

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
soren.enemaerke@gmail.com - 25 Sep 2007 21:49 GMT
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);

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.