COM Interop Part 1 Sample

This sample demonstrates how a C# program can interoperate with an unmanaged COM component.

Security Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To build and run the COM Interop Part 1 samples within Visual Studio

  1. In Solution Explorer, right-click the Interop1 project and click Set as StartUp Project.

  2. In Solution Explorer, right-click the Interop1 project and click Properties.

  3. Open the Configuration Properties folder, and click Debug.

  4. In the Command-Line Arguments property, enter an AVI file such as c:\winnt\clock.avi.

  5. Click OK.

  6. From the Debug menu, click Start Without Debugging.

  7. Repeat the preceding steps for Interop2.

If the QuartzTypeLib.dll included with Interop1 is out of date

  1. In Solution Explorer, open References for Interop1.

  2. Right-click QuartzTypeLib, and click Remove.

  3. Right-click References, and click Add Reference.

  4. In the COM tab, select the component named "ActiveMovie control type library."

  5. Click Select, and then click OK.

  6. Rebuild Interop1.

    Note

    Adding a reference to the component does the same thing as invoking tlbimp at the command line to create QuartzTypeLib.dll (as shown below).

To build and run the COM Interop Part 1 samples from the Command Line

  1. Use the Change Directory command to change to the Interop1 directory.

  2. Type the following:

    tlbimp %windir%\system32\quartz.dll /out:QuartzTypeLib.dll
    csc /r:QuartzTypeLib.dll interop1.cs
    interop1 %windir%\clock.avi
  3. Use the Change Directory command to change to the Interop2 directory.

  4. Type the following:

    csc interop2.cs
    interop2 %windir%\clock.avi