Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

DTE.ExecuteCommand("EditorContextMenus.CodeWindow.GoToHeaderFile") failed

$
0
0

Visual Studio 2010 with SP1, when running a macro

DTE.ExecuteCommand("EditorContextMenus.CodeWindow.GoToHeaderFile")

error msg pop: "Error HRESULT E_FAIL has been returned from a call to a COM component"

I am sure that the current active doc is a cpp file.

and, If I paste the "EditorContextMenus.CodeWindow.GoToHeaderFile" in the Command Window, it worked.

Why it failed in macro ?

Thanks!

the macro script

Imports System
Imports EnvDTE
Imports System.Diagnostics

Public Module swaphcpp

    Function GetOutputWindowPane(ByVal Name As String, Optional ByVal show As Boolean = True) As OutputWindowPane
        Dim window As Window
        Dim outputWindow As OutputWindow
        Dim outputWindowPane As OutputWindowPane

        window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
        If show Then window.Visible = True
        outputWindow = window.Object
        Try
            outputWindowPane = outputWindow.OutputWindowPanes.Item(Name)
        Catch e As System.Exception
            outputWindowPane = outputWindow.OutputWindowPanes.Add(Name)
        End Try
        outputWindowPane.Activate()
        Return outputWindowPane
    End Function

    Sub SwapHeaderSource()
        Dim proj As Project
        Dim doc As Document
        Dim name As String
        Dim window As Window
        Dim target As Object = Nothing
        Dim item As ProjectItem

        doc = DTE.ActiveDocument

        If doc Is Nothing Then
            Exit Sub
        End If


        If (DTE.ActiveWindow Is window) Then
            target = window.Object
        Else
            target = GetOutputWindowPane("List Project")
            target.Clear()
        End If

        name = doc.Name
        name = LCase(name)

        If name.EndsWith(".h") Then
            name = name.Replace(".h", ".cpp")
        ElseIf name.EndsWith(".cpp") Or name.EndsWith(".c") Then
            MsgBox("11111")
            DTE.ExecuteCommand("EditorContextMenus.CodeWindow.GoToHeaderFile")
        End If
    End Sub

End Module



Viewing all articles
Browse latest Browse all 4410