Export (0) Print
Expand All

COM Interop Part 1 Sample 

Download sample

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

Security noteSecurity 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 open the sample file in Solution Explorer

  1. Click Download Sample.

    The File Download message box appears.

  2. Click Open, and on the left column of the zip folder window, click Extract all files.

    The Extraction Wizard opens.

  3. Click Next. You can change the directory that the files will be extracted to, and then click Next again.

    Make sure that the Show extracted files check box is selected, and click Finish.

  4. Double-click the sample's .sln file.

    The sample solution is displayed in Solution Explorer. You might get a security warning that says the solution location is not trusted. Click OK to continue.

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. On 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. On the COM tab, select the component named, "ActiveMovie control type library."

  5. Click Select, and then click OK.

  6. Rebuild Interop1.

    NoteNote

    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
    

See Also

Community Additions

ADD
Show:
© 2014 Microsoft