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

Home Posts Topics Members FAQ

MC++ equivalent to CType in VB

I was following the tutorial given at:

http://msdn.microsoft.com/netframewo...iappsmenus.asp

except writing Managed C++ instead of VB.NET. In particular, under
"Using Menu Groups", they have this code to implement radio-button-like
functionality in menu items:

Private Sub RadioCheck_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles mnuWArrange.Click, mnuWCascade.Click, _
mnuWHorizontal.Click, mnuWVertical.Click
mnuWArrange.Checked = False
mnuWCascade.Checked = False
mnuWHorizontal.Checked = False
mnuWVertical.Checked = False
CType(sender, MenuItem).Checked = True
End Sub
In MC++, is it correct to replace CType() with a __try_cast<>? Is the
only difference between __try_cast<> and dynamic_cast<>, that
__try_cast<> will throw an exception whereas dynamic_cast<> will return
a null pointer?

private:
RadioCheck_Click(System::Object* sender, System::EventArgs* e)
{
mnuWArrange->Checked = false;
mnuWCascade->Checked = false;
mnuWHorizontal->Checked = false;
mnuWVertical->Checked = false;

// this next line is the one in question:
__try_cast<MenuItem*>(sender)->Checked = true;
}

--
Marcus Kwok
Mar 2 '06 #1
2 1437
Correct: __try_cast is the one to use for Managed C++ (2003).
(and safe_cast is the closest equivalent in C++/CLI)
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter

"Marcus Kwok" wrote:
I was following the tutorial given at:

http://msdn.microsoft.com/netframewo...iappsmenus.asp

except writing Managed C++ instead of VB.NET. In particular, under
"Using Menu Groups", they have this code to implement radio-button-like
functionality in menu items:

Private Sub RadioCheck_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles mnuWArrange.Click, mnuWCascade.Click, _
mnuWHorizontal.Click, mnuWVertical.Click
mnuWArrange.Checked = False
mnuWCascade.Checked = False
mnuWHorizontal.Checked = False
mnuWVertical.Checked = False
CType(sender, MenuItem).Checked = True
End Sub
In MC++, is it correct to replace CType() with a __try_cast<>? Is the
only difference between __try_cast<> and dynamic_cast<>, that
__try_cast<> will throw an exception whereas dynamic_cast<> will return
a null pointer?

private:
RadioCheck_Click(System::Object* sender, System::EventArgs* e)
{
mnuWArrange->Checked = false;
mnuWCascade->Checked = false;
mnuWHorizontal->Checked = false;
mnuWVertical->Checked = false;

// this next line is the one in question:
__try_cast<MenuItem*>(sender)->Checked = true;
}

--
Marcus Kwok

Mar 3 '06 #2
David Anton <Da********@discussions.microsoft.com> wrote:
"Marcus Kwok" wrote:
I was following the tutorial given at:

http://msdn.microsoft.com/netframewo...iappsmenus.asp

except writing Managed C++ instead of VB.NET.

In MC++, is it correct to replace CType() with a __try_cast<>? Is the
only difference between __try_cast<> and dynamic_cast<>, that
__try_cast<> will throw an exception whereas dynamic_cast<> will return
a null pointer?

private:
RadioCheck_Click(System::Object* sender, System::EventArgs* e)
{
mnuWArrange->Checked = false;
mnuWCascade->Checked = false;
mnuWHorizontal->Checked = false;
mnuWVertical->Checked = false;

// this next line is the one in question:
__try_cast<MenuItem*>(sender)->Checked = true;
}


Correct: __try_cast is the one to use for Managed C++ (2003).
(and safe_cast is the closest equivalent in C++/CLI)


Thanks.

--
Marcus Kwok
Mar 3 '06 #3

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

Similar topics

0
by: Daniel Lidström | last post by:
Hello! Why is it I am not able to change the order elements are serialized when using XmlSerializer with MC++? Have a look at this code: #using <System.Xml.dll> using namespace...
2
by: SunRise | last post by:
Hi I am creating a C Program , to extract only-Printable-characters from a file ( any type of file) and display them. OS: Windows-XP Ple help me to fix the Errors & Warnings and explain...
2
by: Edward Diener | last post by:
How does one specify in a component that a property is a pointer to another component ? How is this different from a property that is actually an embedded component ? Finally how is one notified in...
3
by: Daniel Lidström | last post by:
I have a CS class I wish to write in MC++: public class UnitsCollection : ArrayList { new public Units this { get { return (Units) base; } set { base = value; } } }
2
by: rmathieu | last post by:
Hi, I want to initialize a static String array in MC++. What I want to do is to initialize my String array like the C# way: new String {"11", "22"} but I could not find an equivalent in MC++. The...
11
by: John E Katich | last post by:
Being an old MFC guy, I'm having a heck of a time working with MC++. Can anybody tell me why the following code outputs 65 instead of an A. And yes I know 65 is the hex value for A, but why is...
7
by: BartMan | last post by:
Greetings, I was looking at the C#'s "lock()" statement, and I was wondering if there was an equivalent or recommended way of doing this in MC++. I have a thread which I am calling a function...
2
by: BartMan | last post by:
Greetings, I am very new to the MC++ 2005 visual studio world, and I was wondering how you do pass by reference under the .Net syntax of mc++ (ie:) To do it in the C# version you would do...
3
by: Bruno LIVERNAIS | last post by:
Hi, We are currently installing a DB2 V9 ESE on a Linux server (RHEL4U4-x86_64). Installation runs successfully on each node. Database user environment is OK and the instance is well created. To...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.