Share via


Displaying Windows Media Encoder

Windows Media Encoder SDK banner art

Using the Windows Media Encoder SDK, you can launch Microsoft Windows Media Encoder, which is useful because you can configure all of the settings in the encoding session and then start the application programmatically, as well as run it in a remote or batch process.

Create an instance of a WMEncoderApp object and use it to acquire a WMEncoder object as illustrated in the following example code. Because the former is an out-of-process component and the latter is an in-process component, do not create a WMEncoderApp object if you do not need to display the UI.

Note You must completely configure the encoding session. If you do not, unpredictable results may occur.

The following examples show how to display Windows Media Encoder programmatically. For end-to-end code examples, see Complete Code Examples.

Visual Basic Example

' Declare variables, which must be done outside of the form procedure.
  Dim EncoderApp As WMEncoderApp
  Dim Encoder As WMEncoder

' Create the WMEncoderApp object.
  Set EncoderApp = New WMEncoderApp

' Retrieve an Encoder object.
  Set Encoder = EncoderApp.Encoder

' Make the UI visible.
  EncoderApp.Visible = True

C++ Example

// Include libraries.
#include <windows.h>
#include "wmencode.h"

// Declare variables.
    HRESULT hr = S_OK;
    IWMEncoder* pEncoder = NULL;
    IWMEncoderApp* pEncoderApp = NULL;

// Initialize the COM library and retrieve a pointer
// to an IWMEncoderApp interface.
    hr = CoInitialize(NULL);
    if ( SUCCEEDED( hr ) )
    {
        hr = CoCreateInstance( CLSID_WMEncoderApp,
                           NULL,
                           CLSCTX_LOCAL_SERVER,
                           IID_IWMEncoderApp,
                           (void**) &pEncoderApp);
    }

// Display the user interface.
    if ( SUCCEEDED( hr ) )
    {
        hr = pEncoderApp->put_Visible(VARIANT_TRUE);
    }

// Acquire an IWMEncoder interface.
    if ( SUCCEEDED( hr ) )
    {
        hr = pEncoderApp->get_Encoder(&pEncoder);
    }

    // Release pointers.
    if ( pEncoder )
    {
        pEncoder->Release();
        pEncoder = NULL;
    }
    if ( pEncoderApp )
    {
        pEncoderApp->Release();
        pEncoderApp = NULL;
    }

C# Example

using WMEncoderLib;

try
{
   // Create WMEncoderApp and WMEncoder objects.
   WMEncoderApp EncoderApp = new WMEncoderApp();
   IWMEncoder Encoder = EncoderApp.Encoder;

   // Display the predefined Encoder UI.
   EncoderApp.Visible = true;
} 

catch (Exception e) 
{  
   // TODO: Handle exceptions.
}

See Also

  • About the Windows Media Encoder SDK