This topic describes how to create an application that uses the Component Platform Interface (CPI).

Required DLLs

Add references to the following DLLs in your project. These DLLs are available in the Tools\Image Manager directory.

  • Microsoft.ComponentStudio.Common.dll

  • Microsoft.ComponentStudio.ComponentPlatformInterface.dll

If you are referencing DLLs in Microsoft Visual Studio, you must also reference the Microsoft.ComponentStudio.ComponentPlatformImplementation.dll or you will not be able to create catalog (.clg) files.

When you run your application, the following additional DLLs are required to be in a path that is accessible to your application:

  • Tools\Image Manager\Microsoft.ComponentStudio.Serializer.dll

  • Tools\Image Manager\Microsoft.ComponentStudio.ComponentPlatformImplementation.dll

In addition, if your application accesses Windows image (.wim) files, you must also include the wimgapi.dll and ssshim.dll references.

  • Tools\<architecture>\ssshim.dll

  • Tools\<architecture>\wimgapi.dll

The Tools\<architecture> directory must be relative to the Tools\Image Manager directory that contains the CPI API DLLs files.

Referencing CPI DLLs

The CPI DLLs are not installed to the Global Assembly Cache (GAC). The CPI DLLs must be in a path that is accessible to your application. If you move your application, you must use the xcopy command to move the DLLs with the application.

To install the CPI DLLs into the GAC, see this Microsoft Web site.

.NET Collection Interfaces

The syntax of some of the CPI API members described in this document refer to .NET collection interfaces. These interfaces are documented on the MSDN site.

CPI Applications Must Target .NET Framework 2.0

Applications that use CPI API must target the .NET Framework version 2.0. Using other versions of the .NET Framework may introduce compatibility issues.

For more information about targeting a specific .NET Framework version, see this Microsoft Web site.

AnswerFile object

Objects that can be created under the AnswerFile object can be created by using collection.Create where collection is the collection of that object type. For example, to create a package action in an answer file, call AnswerFile.PackageActions.Create(). To create a setting override, call AnswerFile.SettingOverrides.Create().

To delete an object, call object.Remove() where object is the name of the object to remove.

Validating Answer Files

You can use the CPI API to programmatically validate an answer file in an environment that supports the .NET Framework. However, if you want to validate an answer file in an environment that does not support managed code and the .NET framework, you can use publicly documented native code interfaces. Sample code that utilizes these interfaces is provided with the Windows OPK and Windows AIK in the Samples directory.

The publicly documented interfaces are documented in the Windows SDK Web site.

Updating the AnswerFileChk source code

You can use the CPI application programming interface (API) to programmatically validate an answer file in an environment that supports the .NET Framework. However, to validate an answer file in an environment that does not support managed code and the .NET Framework, you can use publicly-documented native code interfaces. Sample code that utilizes these interfaces is provided with the Windows OPK and the Windows AIK in the Samples directory.

The AnswerFileChk source always returns 0 if the settings in an answer file are successfully validated. However, AnswerFileChk does not interpret the validation result, which can include warnings and errors. You should modify CImageSettingValidator.cpp to check for the validation result and then return the appropriate value, add additional error handling, or ignore all errors and warnings.

Unloading the schema hive

If an error is encountered after the SMI schema hive is loaded, the application will return without unloading the hive. Before you can run the program again, you must manually unload the schema hive.

  1. Using an account with administrator privileges, run Regedit.exe.

  2. Under HKLM, select Schema_{00000000-0000-0000-0000-000000000000}.

  3. Select File, and then click Unload Hive.

  4. Click Yes to confirm unloading the hive.

You can also update the source code to unload the schema hive by editing CImageSettingValidator.h.

  1. Insert the following line after public: section of CImageSettingValidator class in CImageSettingValidator.h:

    ~CImageSettingValidator();

  2. Insert the following code at the end of CImageSettingValidator.cpp.

    CImageSettingValidator::~CImageSettingValidator()
    {
       this->CloseSchema();
    }
    

Updated source code disclaimer

The AnswerFileChk source code disclaimer should be changed.

Replace:

This sample code is provided only as a reference and should not be used in a production environment.

With:

This sample code is provided only as a reference.