469,608 Members | 1,547 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,608 developers. It's quick & easy.

mixing manged and unmanaged C++ & boxing enums

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

Sep 7 '07 #1
2 2948
search for "How to: Explicitly Request Boxing" in MSDN
--
Sheng Jiang
Microsoft MVP in VC++
"Cartoper" <ca******@gmail.comwrote in message
news:11**********************@o80g2000hse.googlegr oups.com...
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

Sep 7 '07 #2
"Cartoper" <ca******@gmail.comwrote in message
news:11**********************@o80g2000hse.googlegr oups.com...
>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...
--
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?

Sep 8 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by William F. Kinsley | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.