MC++ equivalent to CType in VB

M

Marcus Kwok

I was following the tutorial given at:

http://msdn.microsoft.com/netframew.../library/en-us/dndotnet/html/mdiappsmenus.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;
}
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top