home *** CD-ROM | disk | FTP | other *** search
- /*===========================================================================
- File: VideoPlayer.CPP
-
- Summary: This program demonstrates using a classic COM object
- from the Runtime.
-
- Functions: main
-
- ----------------------------------------------------------------------------
- This file is part of the Microsoft NGWS Samples.
-
- Copyright (C) 1998-2000 Microsoft Corporation. All rights reserved.
- ===========================================================================*/
-
- #using <mscorlib.dll>
- #using "QuartzTypeLib.dll"
-
- using namespace System;
- using namespace System::Runtime::InteropServices;
- using namespace System::Threading;
-
- extern void DisplayUsage();
-
-
- /******************************************************************************
- Function : main
-
- Abstract: This method collects the filename of an AVI to show then creates an
- instance of the Quartz classic COM object. To show the AVI, the program calls
- RenderFile and Run on IMediaControl. Quartz uses its own thread and window
- to display the AVI. The main thread blocks on a ReadLine until the user hits
- enter.
-
- Input Parameters: None
-
- Returns: int: Standard 32 bit process return code.
- ******************************************************************************/
- int main()
- {
- // Check to see if the user passed in a filename
- String* args __gc[] = Environment::GetCommandLineArgs();
- if(args.Length != 2)
- {
- DisplayUsage();
- return 0;
- }
-
- // Second argument is the filename
- String *filename = args[1];
-
- if(filename->Equals(L"/?"))
- {
- DisplayUsage();
- return 0;
- }
-
- // Set thread to be STA instead of MTA
- Thread::CurrentThread->ApartmentState = ApartmentState::STA;
-
- // Create instance of Quartz
- QuartzTypeLib::IMediaControl *mc = new QuartzTypeLib::FilgraphManager();
-
- try
- {
- // Pass in file to RenderFile method on Classic COM object.
- mc->RenderFile(filename);
-
- // Show file.
- mc->Run();
-
- }
- catch(ExternalException* ex)
- {
- if(ex->ErrorCode == 0x80040265)
- {
- // Quartz does not know how to render this file
- Console::WriteLine(L"VideoPlayer does not know how to render this file type.");
- }
- else if(ex->ErrorCode == 0x80040216)
- {
- // Quartz could not find the file
- Console::WriteLine(L"VideoPlayer cannot find the file.");
- }
- else
- Console::WriteLine(L"Unknown error occured.");
-
- return ex->ErrorCode;
- }
-
- // Wait for completion.
-
- Console::WriteLine(L"Hit Enter to exit.");
- Console::ReadLine();
-
- return 0;
- };
-
- void DisplayUsage()
- {
- // User did not provide enough parameters.
- // Display usage.
- Console::WriteLine(L"VideoPlayer: Plays AVI files.");
- Console::WriteLine(L"Usage: VIDEOPLAYER.EXE filename");
- Console::WriteLine(L"where filename is the full path and file name");
- Console::WriteLine(L"of the AVI to display.");
- };