如何使用Visual Studio调试Windows Vista侧栏小工具

One of the ancillary benefits of our Vista Gadget breaking and my email filling up with complaints was that I learned how to debug a Vista Gadget in Visual Studio, so I’m sharing the wealth with everybody.

Vista Gadget中断和我的电子邮件充满投诉的附带好处之一是,我学会了如何在Visual Studio中调试Vista Vista小工具,因此我与所有人分享了财富。

For this exercise you’ll need a copy of Visual Studio 2005 and a broken Vista Gadget, but you can probably adapt it to work with a different tool if you try.

对于本练习,您将需要一个Visual Studio 2005副本和一个损坏的Vista小工具,但是如果尝试尝试,则可以使其适应于其他工具。

Critical Step: Enable Script Debugging

关键步骤:启用脚本调试

Open up Internet Explorer’s Options panel, find the Advanced tab and uncheck the boxes for “Disable script debugging”.

打开Internet Explorer的“选项”面板,找到“高级”选项卡,然后取消选中“禁用脚本调试”框。

image

After you are done debugging you’ll probably want to turn this off, as it can get quite annoying while browsing.

调试完成后,您可能需要关闭此功能,因为浏览时会很烦人。

Open Your Gadget Code

打开小工具代码

After installing your gadget, Windows will unpack and copy the files to a folder in your user profile. We’ll need to find this folder and open the javascript file that makes up the logic for your gadget.

安装小工具后,Windows将解压缩文件并将其复制到用户配置文件中的文件夹中。 我们需要找到此文件夹,然后打开构成小工具逻辑的javascript文件。

Just paste the following into the Explorer address bar:

只需将以下内容粘贴到资源管理器地址栏中:

%LOCALAPPDATA%\Microsoft\Windows Sidebar\Gadgets

%LOCALAPPDATA%\ Microsoft \ Windows边栏\小工具

image

You’ll see a list of directories for all the gadgets installed into your profile. Open up the main javascript file in Visual Studio.

您会看到配置文件中安装的所有小工具的目录列表。 在Visual Studio中打开主要的javascript文件。

Attach to Sidebar Process

附加到侧边栏流程

Next we’ll need to attach to the specific sidebar process for your gadget. (Make sure your gadget is running before you do this step)

接下来,我们需要为您的小工具附加特定的侧边栏流程。 (执行此步骤之前,请确保您的小工具正在运行)

Go to Tools \ Attach to Process or hit Ctrl+Alt+P to bring up the dialog.

转到“工具” \“附加到进程”或按Ctrl + Alt + P弹出对话框。

image

Now you should look for a process named “sidebar.exe” with the title set to the name of your gadget, and then click the Attach button.

现在,您应该查找一个名称设置为小工具名称的名为“ sidebar.exe”的进程,然后单击“附加”按钮。

image
image

For a close-up view, you can see that the gadget is running under a separate process from the main sidebar, but the title is set to “How-To Geek”.

对于特写视图,您可以看到该小工具在与主边栏不同的进程下运行,但是标题设置为“ How-To Geek”。

Now comes the critical step… click to set a breakpoint just to the left of the white area…

现在到了关键步骤…单击以在白色区域的左侧设置一个断点…

image

If all goes well, you will immediately be taken to a new file named something like x-gadget:///main.js and your debugging tools will become active as soon as the breakpoint is hit.

如果一切顺利,您将立即被带到一个名为x-gadget:///main.js之类的新文件,并且在遇到断点时,调试工具将立即激活。

image

Note that you can’t modify this file, but you can use the Immediate Window to test out any code in real-time.

请注意,您不能修改此文件,但是可以使用“即时窗口”实时测试任何代码。

Important Notes

重要笔记

  • When debugging a gadget that polls every so often, it would be wise to set the interval really low so that you don’t have to wait very long for it to trigger.

    在调试一个频繁轮询的小工具时,明智的做法是将时间间隔设置得很低,这样您就不必等待很长的时间来触发它。
  • You can make changes in the original source file, but you will have to close/reopen the gadget and then re-attach to it.

    您可以在原始源文件中进行更改,但是必须关闭/重新打开该小工具,然后重新附加到它。
  • If you get an error about no symbols being loaded, you didn’t follow the first step to enable script debugging.

    如果您收到关于未加载任何符号的错误,则说明您没有按照第一步启用脚本调试。
  • You’ll have to manually enter the names of variables to watch in the Watch box, but you can step through the gadget just like a real debugger should.

    您必须在“监视”框中手动输入要监视的变量的名称,但是您可以像真正的调试器一样逐步执行小工具。

Happy debugging!

调试愉快!

翻译自: https://www.howtogeek.com/howto/windows-vista/how-to-debug-a-windows-vista-sidebar-gadget-with-visual-studio/