// 版權所有(C) Microsoft Corporation。保留所有權利。
// 此代碼的發佈遵從
// Microsoft 公共許可(MS-PL,http://opensource.org/licenses/ms-pl.html)的條款。
//
//版權所有(C) Microsoft Corporation。保留所有權利。
// interop2.cs
// 編譯時使用 “csc interop2.cs”
using System;
using System.Runtime.InteropServices;
namespace QuartzTypeLib
{
// 將 IMediaControl 聲明爲一個從 IDispatch 接口派生的
// COM 接口:
[Guid("56A868B1-0AD4-11CE-B03A-0020AF0BA770"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
interface IMediaControl // 此處不能列出任何基接口
{
// 注意 IUnknown 接口成員未在此處列出:
void Run();
void Pause();
void Stop();
void GetState( [In] int msTimeout, [Out] out int pfs);
void RenderFile(
[In, MarshalAs(UnmanagedType.BStr)] string strFilename);
void AddSourceFilter(
[In, MarshalAs(UnmanagedType.BStr)] string strFilename,
[Out, MarshalAs(UnmanagedType.Interface)]
out object ppUnk);
[return: MarshalAs(UnmanagedType.Interface)]
object FilterCollection();
[return: MarshalAs(UnmanagedType.Interface)]
object RegFilterCollection();
void StopWhenReady();
}
// 將 FilgraphManager 聲明爲 COM 組件類:
[ComImport, Guid("E436EBB3-524F-11CE-9F53-0020AF0BA770")]
class FilgraphManager // 此處不能有基類或
// 接口列表。
{
// 此處不能有任何成員
// 注意,C# 編譯器將爲您添加默認構造函數
//(不帶參數)。
}
}
class MainClass
{
/**********************************************************
摘要:此方法收集要顯示的 AVI 的文件名,
然後創建 Quartz COM 對象的實例。
爲了顯示 AVI,程序對
IMediaControl 調用 RenderFile 和 Run。Quartz 使用自己的線程和窗口來顯示
AVI。主線程阻塞在 ReadLine 上,直到用戶按
Enter 鍵爲止。
輸入參數:要顯示的 avi 文件的位置
返回值:void
*************************************************************/
public static void Main(string[] args)
{
// 檢查用戶是否傳入了文件名:
if (args.Length != 1)
{
DisplayUsage();
return;
}
if (args[0] == "/?")
{
DisplayUsage();
return;
}
String filename = args[0];
// 檢查文件是否存在
if (!System.IO.File.Exists(filename))
{
Console.WriteLine("File " + filename + " not found.");
DisplayUsage();
return;
}
// 創建 Quartz 的實例
// (Calls CoCreateInstance(E436EBB3-524F-11CE-9F53-0020AF0BA770,
// NULL, CLSCTX_ALL, IID_IUnknown,
// &graphManager).):
try
{
QuartzTypeLib.FilgraphManager graphManager =
new QuartzTypeLib.FilgraphManager();
// IMediaControl 接口的 QueryInterface:
QuartzTypeLib.IMediaControl mc =
(QuartzTypeLib.IMediaControl)graphManager;
// 對 COM 接口調用某些方法。
// 將文件傳遞給 COM 對象上的 RenderFile 方法。
mc.RenderFile(filename);
// 顯示文件。
mc.Run();
}
catch(Exception ex)
{
Console.WriteLine("Unexpected COM exception: " + ex.Message);
}
// 等待完成。
Console.WriteLine("Press Enter to continue.");
Console.ReadLine();
}
private static void DisplayUsage()
{
// 用戶未提供足夠的參數。
// 顯示用法。
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 互操作 - 第一部分”示例
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
EJB+JSF開發示例(附源碼)
oecp123
2019-02-23 00:00:51
Struts2攔截器簡單示例
llwbrothers
2019-02-22 22:46:15
ext event grid rowclick 的使用示例
slddyb
2019-02-22 21:37:51
sscanf的用法示例
2WDragon
2019-02-22 21:05:28
Bootstrap模態框的簡單示例
oulafen
2019-02-22 20:10:27
Spring入門示例
hanchengen
2019-02-22 17:48:57
Java優先隊列(PriorityQueue)示例
wx5955e325d6bfb
2019-02-22 17:22:04
Windows CE 6.0註冊表應用示例
chanyinhelv
2019-02-22 16:14:09
BerkeleyDB示例
風火
2019-02-22 13:20:00
find命令用法及示例
Uchiha_Itachi
2019-02-16 13:45:42
grep使用示例
Uchiha_Itachi
2019-02-16 13:45:42
Apache web服務器的相關知識整理及簡要說明
_雨de印記
2018-11-10 02:11:10
在簡書上用Markdown寫表格
larryzhao
2018-10-27 06:47:37
24小時熱門文章