// Copyright (c) Microsoft Corporation. All rights reserved.
// The release of this Code follows
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html) terms.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// Interop2.cs
// Use "CSC interop2.cs" during compilation"
Using system;
Using system. runtime. interopservices;
Namespace quartztypelib
{
// Declare imediacontrol as one derived from the idispatch Interface
// COM interface:
[GUID ("56a868b1-0ad4-11ce-b03a-0020af0ba770 "),
Interfacetype (cominterfacetype. interfaceisdual)]
Interface imediacontrol // no base interface is listed here
{
// Note that iunknown interface members are not listed here:
Void run ();
Void pause ();
Void stop ();
Void getstate ([in] int mstimeout, [out] Out int PFS );
Void renderfile (
[IN, financialas (unmanagedtype. BSTR)] string strfilename );
Void addsourcefilter (
[IN, financialas (unmanagedtype. BSTR)] string strfilename,
[Out, financialas (unmanagedtype. Interface)]
Out object ppunk );
[Return: financialas (unmanagedtype. Interface)]
Object filtercollection ();
[Return: financialas (unmanagedtype. Interface)]
Object regfiltercollection ();
Void stopwhenready ();
}
// Declare filgraphmanager as a COM component class:
[Comimport, GUID ("E436EBB3-524F-11CE-9F53-0020AF0BA770")]
Class filgraphmanager // The base class or
// Interface list.
{
// No member is allowed here
// Note that the C # compiler will add the default constructor for you.
// (Without parameters ).
}
}
Class mainclass
{
/*************************************** *******************
Abstract: This method collects the names of AVI files to be displayed,
Create an instance of the quartz COM object.
To Display AVI
Imediacontrol calls renderfile and run. Quartz uses its own thread and window for display
Avi. The main thread is blocked on Readline until the user presses
Enter.
Input parameter: Location of the AVI file to be displayed
Return Value: void
**************************************** *********************/
Public static void main (string [] ARGs)
{
// Check whether the file name is input by the user:
If (ARGs. length! = 1)
{
Displayusage ();
Return;
}
If (ARGs [0] = "/? ")
{
Displayusage ();
Return;
}
String filename = ARGs [0];
// Check whether the file exists
If (! System. Io. file. exists (filename ))
{
Console. writeline ("file" + filename + "Not found .");
Displayusage ();
Return;
}
// Create a quartz instance
// (Callcocreateinstance (E436EBB3-524F-11CE-9F53-0020AF0BA770,
// Null, clsctx_all, iid_iunknown,
// & Graphmanager ).):
Try
{
Quartztypelib. filgraphmanager graphmanager =
New quartztypelib. filgraphmanager ();
// QueryInterface of the imediacontrol interface:
Quartztypelib. imediacontrol MC =
(Quartztypelib. imediacontrol) graphmanager;
// Call some methods on the COM interface.
// Pass the file to the renderfile method on the COM object.
MC. renderfile (filename );
// Display the file.
MC. Run ();
}
Catch (exception ex)
{
Console. writeline ("unexpected com exception:" + ex. Message );
}
// Wait for completion.
Console. writeline ("press enter to continue .");
Console. Readline ();
}
Private Static void displayusage ()
{
// The user does not provide enough parameters.
// Display usage.
Console. writeline ("videoplayer: plays AVI files .");
Console. writeline ("Usage: videoplayer. exe filename ");
Console. writeline ("where filename is the full path and ");
Console. writeline ("File Name of the AVI to display .");
}
}
Com interoperability-Part 1 "Example