mixing manged and unmanaged C++ & boxing enums

C

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?

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:blush:ldSyntax. Thus I have a feeling there
is a new way of doing it.

Cartoper
 
D

Doug Semler

Cartoper said:
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:blush:ldSyntax. 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...


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

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