home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / VideoPlayer / VideoPlayer.cpp < prev   
Encoding:
C/C++ Source or Header  |  2000-06-23  |  2.8 KB  |  106 lines

  1. /*===========================================================================
  2.   File:      VideoPlayer.CPP
  3.  
  4.   Summary:   This program demonstrates using a classic COM object 
  5.              from the Runtime.
  6.  
  7.   Functions: main
  8.  
  9. ----------------------------------------------------------------------------
  10.   This file is part of the Microsoft NGWS Samples.
  11.  
  12.   Copyright (C) 1998-2000 Microsoft Corporation.  All rights reserved.
  13. ===========================================================================*/
  14.  
  15. #using <mscorlib.dll>
  16. #using "QuartzTypeLib.dll"
  17.  
  18. using namespace System;
  19. using namespace System::Runtime::InteropServices;
  20. using namespace System::Threading;
  21.  
  22. extern void DisplayUsage();
  23.  
  24.  
  25. /******************************************************************************
  26. Function : main
  27.  
  28. Abstract: This method collects the filename of an AVI to show then creates an 
  29. instance of the Quartz classic COM object.  To show the AVI, the program calls
  30. RenderFile and Run on IMediaControl.  Quartz uses its own thread and window
  31. to display the AVI.  The main thread blocks on a ReadLine until the user hits
  32. enter.
  33.  
  34. Input Parameters: None
  35.  
  36. Returns: int: Standard 32 bit process return code.
  37. ******************************************************************************/
  38. int main()
  39. {
  40.     // Check to see if the user passed in a filename
  41.     String* args __gc[] = Environment::GetCommandLineArgs();
  42.     if(args.Length != 2)
  43.     {
  44.         DisplayUsage();
  45.         return 0;
  46.     }
  47.  
  48.     // Second argument is the filename
  49.     String *filename = args[1];
  50.     
  51.     if(filename->Equals(L"/?"))
  52.     {
  53.         DisplayUsage();
  54.         return 0;
  55.     }
  56.  
  57.     // Set thread to be STA instead of MTA
  58.     Thread::CurrentThread->ApartmentState = ApartmentState::STA;
  59.  
  60.     // Create instance of Quartz
  61.     QuartzTypeLib::IMediaControl *mc = new QuartzTypeLib::FilgraphManager();
  62.  
  63.     try
  64.     {
  65.         // Pass in file to RenderFile method on Classic COM object.
  66.         mc->RenderFile(filename);
  67.  
  68.         // Show file.
  69.         mc->Run();
  70.  
  71.     }
  72.     catch(ExternalException* ex)
  73.     {
  74.         if(ex->ErrorCode == 0x80040265)
  75.         {
  76.             // Quartz does not know how to render this file
  77.             Console::WriteLine(L"VideoPlayer does not know how to render this file type.");
  78.         }
  79.         else if(ex->ErrorCode == 0x80040216)
  80.         {
  81.             // Quartz could not find the file
  82.             Console::WriteLine(L"VideoPlayer cannot find the file.");
  83.         }
  84.         else
  85.             Console::WriteLine(L"Unknown error occured.");
  86.         
  87.         return ex->ErrorCode;
  88.     }
  89.  
  90.     // Wait for completion.
  91.     
  92.     Console::WriteLine(L"Hit Enter to exit.");
  93.     Console::ReadLine();
  94.     
  95.     return 0;
  96. };
  97.  
  98. void DisplayUsage()
  99. {
  100.     // User did not provide enough parameters.
  101.     // Display usage.
  102.     Console::WriteLine(L"VideoPlayer: Plays AVI files.");
  103.     Console::WriteLine(L"Usage: VIDEOPLAYER.EXE filename");
  104.     Console::WriteLine(L"where filename is the full path and file name");
  105.     Console::WriteLine(L"of the AVI to display.");
  106. };