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.

mixing manged and unmanaged C++ & boxing enums

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cartoper - 07 Sep 2007 17:53 GMT
I am working in VS2005 (.Net 2.0).

I have a unmanaged C++ class that will be used by C#, once I get to
that point.  I would like to throw a System::ApplicationException from
the unmanaged code, is there any problems with this?

I am formating a string in one of these throws where I am using
String::Format and one of the values is a unmanaged enum (ie int).
How do I go about boxing it to use it in the String::Format call?
When I try to use __box(result), I get an error C4980: '__box' : use
of this keyword requires /clr:oldSyntax.  Thus I have a feeling there
is a new way of doing it.

Cartoper
Sheng Jiang[MVP] - 07 Sep 2007 19:33 GMT
search for "How to: Explicitly Request Boxing" in MSDN

Signature

Sheng Jiang
Microsoft MVP in VC++

> I am working in VS2005 (.Net 2.0).
>
[quoted text clipped - 10 lines]
>
> Cartoper
Doug Semler - 08 Sep 2007 15:48 GMT
>I am working in VS2005 (.Net 2.0).
>
> I have a unmanaged C++ class that will be used by C#, once I get to
> that point.  I would like to throw a System::ApplicationException from
> the unmanaged code, is there any problems with this?

How would your unmanaged C++ code know anything about
System::ApplicationException (or gcnew or anything like that)?  Are you sure
you are really in unmanaged code when doing the throw???

IIRC,  if an SEH exception is thrown from unmanaged code (via RaiseException
or C++ "throw"), it gets converted into a
System::Runtime::InteropServices::SEHException in the managed code...

> I am formating a string in one of these throws where I am using
> String::Format and one of the values is a unmanaged enum (ie int).
> How do I go about boxing it to use it in the String::Format call?
> When I try to use __box(result), I get an error C4980: '__box' : use
> of this keyword requires /clr:oldSyntax.  Thus I have a feeling there
> is a new way of doing it.

I thought C++/CLI would implicitly box ints now.

String::Format("{0}", (int)myResult);
or even
((int)myResult).ToString();

should work just fine...

Signature

Doug Semler, MCPD
a.a. #705, BAAWA.  EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?


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.