如何在VS2010 C ++宏中使用DTE.ExecuteCommand(“Edit.GoToDefinition”)? [英] How do I use DTE.ExecuteCommand("Edit.GoToDefinition") in a VS2010 C++ macro?

查看:319
本文介绍了如何在VS2010 C ++宏中使用DTE.ExecuteCommand(“Edit.GoToDefinition”)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我录制了一个宏,其中包含F12(Go To Definition)的按键,但记录会省略传递给DTE.ExecuteCommand的第二个参数,导致宏在执行期间崩溃。推测第二个arg是我想要找到的函数的名字,但我不知道如何获取和传递值。如果我选择函数或方法名(但不是args或类前缀),我可以使用DTE.ActiveDocument.Selection.Text.ToString传递选择,而不是跳转到定义,它返回两者。 h文件和.cpp文件。

I recorded a macro that includes a keypress of F12 (Go To Definition), but the recording omits the second parameter that is passed to DTE.ExecuteCommand, causing the macro to crash during execution. Presumably the second arg is the name of the function I want to find, but I can't figure out how to get and pass the value. If I select the function or method name (but not the args or the class prefix), I can use DTE.ActiveDocument.Selection.Text.ToString to pass the selection, but instead of jumping to the definition, it returns the both the .h file and the .cpp file in the Find Symbol Results window.

(我不确定选择是否真的是我想要的,虽然我可以得到宏选择正确的事情,如果这是要走的路。有什么办法可以看看F12传递的是什么,只是为了看看它是什么样子?或者更好的是,找出什么程序对象F12传递?

(And I'm not sure selection is really what I want, though I could probably get the macro to select the "right thing" if that's the way to go. Is there any way to see what F12 is passing, just to see what it looks like? Or better yet, find out what programmatic object F12 is passing?

Vs2010 Pro

Vs2010 Pro

推荐答案

通过IVsUIShell工作运行相同的命令:

Turns out running the same command via IVsUIShell works:

    Dim cmd As EnvDTE.Command
    Dim shell As Microsoft.VisualStudio.Shell.Interop.IVsUIShell
    Dim arg As Object
    Dim guid As System.Guid
    Dim serviceProvider As System.IServiceProvider

    serviceProvider = New Microsoft.VisualStudio.Shell.ServiceProvider(CType(DTE, Microsoft.VisualStudio.OLE.Interop.IServiceProvider))
    shell = serviceProvider.GetService(GetType(Microsoft.VisualStudio.Shell.Interop.SVsUIShell))
    cmd = DTE.Commands.Item("Edit.GoToDefinition", 0)
    guid = New System.Guid(cmd.Guid)
    shell.PostExecCommand(guid, cmd.ID, 0, arg)

如在Visual Commander中。要从Visual Studio宏IDE运行它,您需要添加对

The code works as is in Visual Commander. To run it from Visual Studio macros IDE, you need to add references to

Microsoft.VisualStudio.OLE.Interop.dll
Microsoft.VisualStudio.Shell.10.0.dll
Microsoft.VisualStudio.Shell.Interop.dll
Microsoft.VisualStudio.Shell.Interop.8.0.dll
Microsoft.VisualStudio.Shell.Interop.9.0.dll

要添加引用,首先需要将这些文件复制到 Microsoft Visual Studio 10.0 \Common7\IDE\PublicAssemblies目录

And to add references you first need to copy these files to the Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies directory.

这篇关于如何在VS2010 C ++宏中使用DTE.ExecuteCommand(“Edit.GoToDefinition”)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆