共用方式為


Getting Progress Information from an Installation Package

Starting in Visual Studio 2008 SDK SP1, redistributable packages use an installation chaining mechanism named IronSpigot. This mechanism enables installation executables to discover the progress of the installation of the redistributable packages. When you call one of these installation packages from an unmanaged C++ executable, you can display the progress of the redistributable installation together with the progress of your executable.

Installation Packages That Use the IronSpigot Chainer

The following Visual Studio 2008 SDK SP1 installation packages use the IronSpigot chaining mechanism:

  • Visual Studio 2008 Shell (integrated mode) with Service Pack 1 Redistributable Package

  • Visual Studio 2008 Shell (isolated mode) with Service Pack 1 Redistributable Package

Getting Progress Information from the IronSpigot Chainer

To get progress information from the IronSpigot chainer, you must include the header file MmioChainer.h, which can be found in Visual Studio SDK installation path\VisualStudioIntegration\Common\Inc\.

To use the chainer, subclass the MmioChainer class that is defined in the header file, and a constructor that has two string parameters. The exact form of these strings is not important.

注意

You must run the following code as an administrator.

#include <atlstr.h>
#include <stdlib.h>
#include "MmioChainer.h"

class TestChainer : public IronSpigot::MmioChainer
{
TestChainer() : IronSpigot::MmioChainer(L“TheSectionName”, L“TheEventName”)
{}
}

In the subclass, implement the OnProgress and OnFinished methods to get the progress of the installation.

virtual void OnProgress(unsigned char soFar)
{
//add your own code here
printf("Progress: %i  ", soFar);
}
virtual void OnFinished(HRESULT hr)
{
//add your own code here
printf("Finished: 0x%x\r\n", hr);
}

Progress information will be returned as an integer from 0 (not started) to 255 (completed).

In the subclass you must also implement a Launch method that invokes the installation process and performs basic cleanup when the process is terminated.

bool Launch()
{
STARTUPINFO si = {0};
si.cb = sizeof(si);
PROCESS_INFORMATION pi = {0};

WCHAR cmd[_MAX_PATH] = {0};
wcscpy_s(cmd, _MAX_PATH, L"vs_shell_isolated.enu.exe -q -pipe TheSectionName");

BOOL b = ::CreateProcess(NULL, 
cmd,
NULL, NULL, FALSE, 0, NULL, NULL, 
&si,
&pi);
if (b != 0)
{
Run(pi.hProcess);

::CloseHandle(pi.hThread);
::CloseHandle(pi.hProcess);
}
else
{
printf("CreateProcess failed");
}
return b;
}

To call this code, instantiate the subclass and call the Launch method.

TestChainer *chainer = new TestChainer();
chainer->Launch();

See Also

Other Resources

Installing VSPackages