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
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
>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?