473,324 Members | 2,268 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,324 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 3128
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.