Macros For converting C++ extensions to cli

Public Module ConversionModule

    Public Sub UpdateToCLI()

        SeachAndReplaceDocumentPointers("System::")

        SeachAndReplaceDocumentPointers("nsoftware::IPWorksSSL::IPWorksSSLException")
        SeachAndReplaceDocumentPointers("nsoftware::IPWorksSSL::HttpsStatusEventArgs")
        SeachAndReplaceDocumentPointers("nsoftware::IPWorksSSL::HttpsStatusEventArgs")
        SeachAndReplaceDocumentPointers("C1::Win::C1FlexGrid::")
        SeachAndReplaceDocumentPointers("C1::")

        FindReplace("__gc ", "ref ")
        FindReplace("__property", "property")
        FindReplace("__try_cast", "safe_cast")
        FindReplace(" S""", " """)
        FindReplace("(S""", "(""")
        'FindReplace("    S"",""")

        NewToGCnew("System") 
        NewToGCnew("nsoftware")
        NewToGCnew("C1FlexGrid")
        NewToGCnew("C1::")


        ReplaceTypeOf()
        ReplaceItemOf()
        FindReplace("->ItemOf", "->default")
        FindReplace("->Item", "->default")


    End Sub

    Sub SeachAndReplaceDocumentPointers(ByVal ManagedNameSpaceToken As String)

        SeachAndReplacePointers(ManagedNameSpaceToken + "*\*", "^")
        SeachAndReplacePointers(ManagedNameSpaceToken + "\*", "^")
        SeachAndReplacePointers(ManagedNameSpaceToken + "*^ &", "%")
        SeachAndReplacePointers(ManagedNameSpaceToken + "*^&", "%")
        SeachAndReplacePointers(ManagedNameSpaceToken + "*^ \*", "%")
        SeachAndReplacePointers(ManagedNameSpaceToken + "*^\*", "%")
    End Sub
    Sub SeachAndReplacePointers(ByVal What As String, ByVal ReplaceWith As String)
        Do
            DTE.Windows.Item(DTE.ActiveDocument.Name).Activate()
            DTE.Find.FindWhat = What
            DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
            DTE.Find.MatchCase = False
            DTE.Find.MatchWholeWord = False
            DTE.Find.Backwards = False
            DTE.Find.MatchInHiddenText = False
            DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
            DTE.Find.Action = vsFindAction.vsFindActionFind
            If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then
                Exit Do
            Else
                DTE.ActiveDocument.Selection.CharRight()
                DTE.ActiveDocument.Selection.DeleteLeft()
                DTE.ActiveDocument.Selection.Text = ReplaceWith
            End If
        Loop

    End Sub
    Sub FindReplace(ByVal What As String, ByVal ReplaceWith As String)
        DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
        DTE.Find.FindWhat = What
        DTE.Find.ReplaceWith = ReplaceWith
        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.MatchCase = False
        DTE.Find.MatchWholeWord = False
        DTE.Find.MatchInHiddenText = False
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
        DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
        DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
        DTE.Find.Execute()
    End Sub
    Sub NewToGCnew(ByVal Type As String)

        Do
            DTE.Find.FindWhat = " new " + Type + "*"
            DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
            DTE.Find.MatchCase = False
            DTE.Find.MatchWholeWord = False
            DTE.Find.Backwards = False
            DTE.Find.MatchInHiddenText = False
            DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
            DTE.Find.Action = vsFindAction.vsFindActionFind
            If (Not (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound)) Then
                DTE.Find.Action = vsFindAction.vsFindActionReplace
                DTE.Find.ReplaceWith = " gcnew "
                DTE.Find.FindWhat = " new "
                DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
                DTE.Find.MatchCase = False
                DTE.Find.MatchWholeWord = False
                DTE.Find.Backwards = False
                DTE.Find.MatchInHiddenText = False
                DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
                DTE.Find.Execute()
            Else
                Exit Do
            End If
        Loop
    End Sub
    Sub ReplaceTypeOf()
        Do
            DTE.Find.FindWhat = "__typeof(*)"
            DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
            DTE.Find.MatchCase = False
            DTE.Find.MatchWholeWord = False
            DTE.Find.Backwards = False
            DTE.Find.MatchInHiddenText = False
            DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
            DTE.Find.Action = vsFindAction.vsFindActionFind
            If (Not (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound)) Then
                DTE.ActiveDocument.Selection.CharLeft()
                DTE.ActiveDocument.Selection.CharRight(True, 9)
                DTE.ActiveDocument.Selection.Delete()

                DTE.Find.FindWhat = ")"
                DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
                DTE.Find.MatchCase = False
                DTE.Find.MatchWholeWord = False
                DTE.Find.Backwards = False
                DTE.Find.MatchInHiddenText = False
                DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
                DTE.Find.Action = vsFindAction.vsFindActionFind
                If (Not (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound)) Then
                    DTE.ActiveDocument.Selection.Text = "::typeid"
                End If
            Else
                Exit Do
            End If
        Loop
    End Sub
    Sub ReplaceItemOf()
        Do
            DTE.Find.FindWhat = "get_ItemOf"
            DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
            DTE.Find.MatchCase = False
            DTE.Find.MatchWholeWord = False
            DTE.Find.Backwards = False
            DTE.Find.MatchInHiddenText = False
            DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
            DTE.Find.Action = vsFindAction.vsFindActionFind
            If (Not (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound)) Then
                DTE.ActiveDocument.Selection.Delete()
                DTE.ActiveDocument.Selection.Text = "default["

                DTE.Find.FindWhat = ")"
                DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
                DTE.Find.MatchCase = False
                DTE.Find.MatchWholeWord = False
                DTE.Find.Backwards = False
                DTE.Find.MatchInHiddenText = False
                DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
                DTE.Find.Action = vsFindAction.vsFindActionFind
                If (Not (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound)) Then
                    DTE.ActiveDocument.Selection.Text = "]"
                End If
            Else
                Exit Do
            End If
        Loop

    End Sub
    Sub WrapCStringWithSystemString()

        DTE.ActiveDocument.Selection.Text = " gcnew System::String( " + DTE.ActiveDocument.Selection.Text + " )"
    End Sub
    Sub WrapSystemStringWithCString()

        DTE.ActiveDocument.Selection.Text = " CString( " + DTE.ActiveDocument.Selection.Text + " )"
    End Sub
    Sub WrapValueArray()
        DTE.ActiveDocument.Selection.Text = "array< " + DTE.ActiveDocument.Selection.Text + " > ^"
    End Sub
    Sub WrapHandle()
        DTE.ActiveDocument.Selection.Text = "(HWND)" + DTE.ActiveDocument.Selection.Text + ".ToPointer()"
    End Sub
    Sub ConvertToNull()
        DTE.Find.Action = vsFindAction.vsFindActionFind
        DTE.Find.FindWhat = "NULL"

        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.MatchCase = False
        DTE.Find.MatchWholeWord = False
        DTE.Find.MatchInHiddenText = False
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
        DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
        DTE.Find.Action = vsFindAction.vsFindActionFind
        DTE.Find.Execute()
        DTE.ActiveDocument.Selection.Text = "nullptr"
    End Sub
    Sub updateDefaultI()
        DTE.Find.Action = vsFindAction.vsFindActionFind
        DTE.Find.FindWhat = "default(i)"

        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.MatchCase = False
        DTE.Find.MatchWholeWord = False
        DTE.Find.MatchInHiddenText = False
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
        DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
        DTE.Find.Action = vsFindAction.vsFindActionFind
        DTE.Find.Execute()
        DTE.ActiveDocument.Selection.Text = "default[i]"
    End Sub
    Sub UpdateToGCNew()

        DTE.Find.Action = vsFindAction.vsFindActionFind

        DTE.Find.FindWhat = " new "
        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.MatchCase = False
        DTE.Find.MatchWholeWord = False
        DTE.Find.Backwards = False
        DTE.Find.MatchInHiddenText = False
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
        DTE.Find.Execute()
        DTE.ActiveDocument.Selection.Text = " gcnew "

    End Sub
    Sub UpdateHat()

        DTE.Find.Action = vsFindAction.vsFindActionFind

        DTE.Find.FindWhat = "\*"
        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.MatchCase = False
        DTE.Find.MatchWholeWord = False
        DTE.Find.Backwards = False
        DTE.Find.MatchInHiddenText = False
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
        DTE.Find.Execute()
        DTE.ActiveDocument.Selection.Text = "^"

    End Sub
    Sub UpdateHatAndGcNew()
        UpdateHat()
        UpdateToGCNew()
    End Sub
End Module
Comments [0]
All comments require the approval of the site owner before being displayed.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview