473,231 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

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 3125
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Andreas Huber | last post by:
What follows is a discussion of my experience with .NET generics & the ..NET framework (as implemented in the Visual Studio 2005 Beta 1), which leads to questions as to why certain things are the...
0
by: P Reddy | last post by:
Hi All, Greetings!!! I have a question. Please respond.... I am trying to write a C# component that need to inherit some of the the interfaces from unmanged code(VC). I think one way to...
2
by: Daniel Mori | last post by:
Hi, Im hoping someone can give me some advice. Im doing some development using VS Whidbey 2005 beta 1. Im about to implement some highly time critical code related to a managed collection of...
4
by: William F. Kinsley | last post by:
My understanding is that when I re-compile a existing MFC application with the /clr switch, that the code generated is managed(with some exceptions) but that the data isn't, i.e. not garbage...
2
by: MR | last post by:
help! I have an unmanaged DLL that I do not have the source code, so i can't recompile or make changes. the DLL requires a callback function. I would like to implement the callback method in a...
7
by: Tim | last post by:
When there is a need to pass some dynamic information between 2 managed assemblies, the "Dictionary object" in Generic form can be used as a method parameter to pass the information. The...
6
by: bill | last post by:
All, I have an unmanaged data structure that I use to pass to an umanaged DLL written in C. This works great. The structure looks sort of like this: unsafe public struct Inputs { .....
1
by: AlwaysPerplexed | last post by:
Hi, I'm somewhat stuck and could really appreciate some help. I'm writing a little program using the OpenCV libraries, I started this as a Win32 Console Application and everything worked fine. I...
0
by: HeroOfSpielburg | last post by:
Hello, I'm new to the realm of .NET application creation, so please forgive my ignorance. I have been tasked with debugging a problem that arises with using a DLL that contains managed and...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.