473,842 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I do __typeof(__box MyValueType) in the new C++/CLI syntax ?

12 6975
Hi Bern,
>How do I do __typeof(__box MyValueType) in the new C++/CLI syntax ?
Since the new C++/CLI doesn't use the __box keyword to do the boxing, I am
afraid there seems not existed an one to one translation, my idea is as the
following:

((MyValueType^) MyValueTypeVar)->GetType()
Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 12 '06 #2
Hi Gary!
>How do I do __typeof(__box MyValueType) in the new C++/CLI syntax ?

Since the new C++/CLI doesn't use the __box keyword to do the boxing, I am
afraid there seems not existed an one to one translation, my idea is as the
following:

((MyValueType^) MyValueTypeVar)->GetType()
The difference between "->GetType()" and "__typeof" is that
"->GetType()" requires an instance of an object while "__typeof" does not.

Therefor the equivalent of "__typeof" in C++/CLI is "::typeid".

See: typeof Goes to T::typeid
http://msdn2.microsoft.com/en-us/lib...60(VS.80).aspx

Greetings
Jochen
Dec 12 '06 #3
Thanks for the suggestion, Jochen.

So the equivalent expression could be:

MyValueType::ty peid
Best regards,

Gary Chang
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 12 '06 #4

But I don't want the System::Type object that represents the type of MyValueType.
I want the System::Type object that represent the boxed form of MyValueType.
So short of using an instance, how do I get it?

-Bern
Thanks for the suggestion, Jochen.

So the equivalent expression could be:

MyValueType::ty peid

Best regards,

Gary Chang
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...s/default.aspx
#notif
ications.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.

Dec 12 '06 #5
Bern McCarty wrote:
>
But I don't want the System::Type object that represents the type of
MyValueType. I want the System::Type object that represent the boxed
form of MyValueType. So short of using an instance, how do I get it?
That's an interesting question. My tip would be this:

tyepdef MyValueType^ MyValueTypeBoxe d;
MyValueTypeBoxe d::typeid

Example:
typedef System::Int32^ T;
Type^ t = T::typeid;

However, when I do this in VC2003, it prints False:
Console::WriteL ine(__typeof(__ box int)->IsValueType) ; // "False"

When I do this in VS2005, it prints True:
int i;
int^ bi = i;
Console::WriteL ine(bi->GetType()->IsValueType) ; // "True"

and this prints True as well:

typedef System::Int32^ T;
Console::WriteL ine(T::typeid->IsValueType) ; // "True"

So it seems to work differently in .NET 2.0. A boxed value type seems to
report the same as the value type itself. This puzzles me...

Tom
Dec 13 '06 #6
Hi Bern!
But I don't want the System::Type object that represents the type of
MyValueType. I want the System::Type object that represent the boxed
form of MyValueType. So short of using an instance, how do I get it?
The question is: Why do you need this?

Or what is the background of your question?

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Dec 13 '06 #7

It is being used it in the overrides of virtual bool Equals(Object __gc*)
in some of our value types:
public: virtual bool Equals(System:: Object * obj)
{
if (obj == NULL || __typeof(__box LineStyleID) != obj->GetType())
return false;
....
Hi Bern!
>But I don't want the System::Type object that represents the type of
MyValueType. I want the System::Type object that represent the boxed
form of MyValueType. So short of using an instance, how do I get it?
The question is: Why do you need this?

Or what is the background of your question?

My blog about Win32 and .NET
http://blog.kalmbachnet.de/


Dec 14 '06 #8
Bern McCarty wrote:
>
It is being used it in the overrides of virtual bool Equals(Object
__gc*) in some of our value types:
public: virtual bool Equals(System:: Object * obj)
{
if (obj == NULL || __typeof(__box LineStyleID) != obj->GetType())
return false;
It looks like it is not possible to get a typeid for a boxed value type
in C++/CLI. I couldn't find a way of doing that, and the draft standard
doesn't specify this either.

But even if you could do that, I don't think your logic is correct.
That's because __box(a_value)->GetType() is not __typeof(__box
ValueType), but __typeof(ValueT ype) itself, even in VC++ 2003 or with
/clr::OldSyntax:

__value struct MyValueClass
{
int i;
};

int _tmain()
{
MyValueClass v;
__box MyValueClass* boxed_v = __box(v);
Console::WriteL ine(boxed_v->GetType()->Equals(
__typeof(MyValu eClass)));
// this is True
Console::WriteL ine(boxed_v->GetType()->Equals(
__typeof(__box MyValueClass))) ;
// this is False
}
Tom
Dec 14 '06 #9
Hi Bern!
public: virtual bool Equals(System:: Object * obj)
{
if (obj == NULL || __typeof(__box LineStyleID) != obj->GetType())
return false;
What's wrong with:

public: virtual bool Equals(System:: Object^ obj)
{
if (obj == nullptr || LineStyleID::ty peid != obj->GetType())
return false;
return true;
}

???

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Dec 15 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
510
by: dgaucher | last post by:
Hi, I want to consume a Web Service that returns a choice, but my C++ client always receives the same returned type. On the other hand, when I am using a Java client, it is working fine (of course, the generated proxy is not the same). When I am looking at the C++ generated code, it seems fine, but when I am executing the code, I always get the first choice type.
2
1915
by: Lev | last post by:
Hi, I have some code that does reflection on an assembly I load. When I try to get the attributes on one of the methods implemented in the assembly, the MC++ version does not return anything. See code below: Object __gc* memberAttributes = info->GetCustomAttributes(__typeof(EntryPointAttribute), false);
1
2554
by: Ghost | last post by:
Hi all, I wrote a program in C# and now I have to "translate" it i visual C++ (MFC) using .NET, but I had a little problem: *ERRORS* error C3181: 'CTestDlg' : invalid operand for __typeof, expected fully defined managed type error C3363: 'void CTestDlg::BtnAboutClick(System::Object __g *,System::EventArgs __gc *)' : cannot create a delegate handler fo 'System::EventHandler' from a non-member function or a member of a
6
1127
by: Jeremy | last post by:
Hello all, I'm having some problems working with enumerations. A function call to a 3rd party dll has in it's parameter list an enumerated type which connects me to a COM port. I'm trying to convert a stored parameter from a database into this enumerated value and can't seem to get anything to work. In some VB.NET code that was written, it works fine and that's the frustrating part. I've included some code below: Old vb.net code...
1
3744
by: Gary | last post by:
I have a strange compile error. C2664 cannot convert parameter 2 from int to int... Earlier in my code I was setting up my dataset... I add an int field like so... Books->Columns->Add("Volume",System::Type::GetType(S"System.Int32")); Then below I try to add an int value to it.
0
1586
by: Stephen Carson | last post by:
I cannot see a browsable property I have added in the Properties Window. Using C++ in Visual Studio .NET 2003 I have added a property to my managed class: public:
1
1235
by: Marcus Kwok | last post by:
I wrote a little test program to demonstrate what may be a misunderstanding on my part in the behavior of ArrayList::Sort(). I defined a class (Test) that has two data members: a System::String* (name) and a double value. Test implements IComparable, so I made the CompareTo() function sort first by name, then by the value of the double. When I run the code below, it sorts by name correctly, but it does not sort correctly the items...
1
2680
by: Bill Medland | last post by:
I am trying to do some P/Invoke custom marshaling and am looking for a little help on custom marshaling a value type. I am working based on Kate Gregory's "Arranging Custom Marshaling With P/Invoke", which is unfortunately in C++ with managed extensions; I am working in C#. As with Kate's example I want to marshal from a System.DateTime to a proprietary format. However I cannot figure out how to tell the system to box the DateTime. ...
1
1793
by: ramasubramanian.rahul | last post by:
hi people.. dont know if this the right forum for this doubt ... so sorry if i am mis-posting... i was looking at the way glib 2.10.3 does export optimization using a list of "to be exposed" function names in a file caleed glib.symbols. this file is used by a perl script to generate a header a .c file ( galias.h and galiasdefs.c). This files essentially enusres default visibility for these functions (using the __attribute__((default))__...
0
9709
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10934
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10303
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9446
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7853
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5694
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4085
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.