Share via


_IWMEncBasicEditEvents Interface

Windows Media Encoder SDK banner art

The _WMEncBasicEditEvents interface is a callback object to which event notifications are sent. Use this interface to respond to state changes in the IWMEncBasicEdit and IWMEncStreamEdit interfaces.

Note Do not perform blocking actions when events are being fired. You will not be able to receive the events in a timely manner. For example, do not create a modal dialog box when events are being fired.

In addition to the methods inherited from IDispatch, the _IWMEncBasicEditEvents interface exposes the following methods.

Method Description
OnError Indicates that a run-time error has occurred.
OnStateChange Indicates whether postprocessing has been started or stopped.

Example Code

#include <windows.h>
#include <conio.h>
#include <atlbase.h>    // Includes CComBSTR and CComVariant.

// Prepare ATL.
CComModule _Module;
#include <atlcom.h>
#include "WMEncode.h"
#include "WMSEncid.h"

//============================================================
// CBasicEditCallBack Class Implementation
//============================================================
#define EVENT_ID        101
#define LIB_VERMAJOR    1
#define LIB_VERMINOR    0

class CBasicEditCallBack : public IDispEventImpl< EVENT_ID, 
                                              CBasicEditCallBack,                                                 
                                              &DIID__IWMEncBasicEditEvents,
                                              &LIBID_WMEncoderLib,
                                              LIB_VERMAJOR, 
                                              LIB_VERMINOR >
{
private:
    WMENC_BASICEDIT_STATE m_enumState;

public:
    // Define the event sink map which determines the events
    // that the application receives.
    BEGIN_SINK_MAP(CBasicEditCallBack)
        SINK_ENTRY_EX( EVENT_ID, 
                       DIID__IWMEncBasicEditEvents,
                       DISPID_BASICEDITEVENT_STATECHANGE,
                       OnStateChange )
    END_SINK_MAP()

    // Implement the event handler for the OnStateChange event.
    STDMETHOD( OnStateChange )( WMENC_BASICEDIT_STATE enumState )
    {
        m_enumState = enumState;
        return S_OK;
    }

    // Override the base class virtual function to provide information
    // on the implemented event handlers.
    HRESULT GetFuncInfoFromId( const IID& iid, DISPID dispidMember,
                               LCID lcid, _ATL_FUNC_INFO& info )
    {
        if (InlineIsEqualGUID( iid, DIID__IWMEncBasicEditEvents ) )
        {
            info.cc = CC_STDCALL;
            info.vtReturn = VT_ERROR;
            switch(dispidMember)
            {
            // Descibe the parameters of the
            // OnStateChange event handler.
            case DISPID_BASICEDITEVENT_STATECHANGE:
                info.nParams = 1;
                info.pVarTypes[0] =  VT_I4;
                return S_OK;
            
            default:
                return E_FAIL;
            }
        }
        return E_FAIL;
    }

    // Link the events to the basic edit instance.
    HRESULT Init( IWMEncBasicEdit* pBasicEdit )
    {
        HRESULT hr = DispEventAdvise( pBasicEdit );
        if( FAILED( hr ) ) 
        {
            // TODO: Handle failure condition.
        }
        return hr;
    }

    // Detach the event sink from the encoder instance.
    HRESULT ShutDown( IWMEncBasicEdit* pBasicEdit )
    {
        HRESULT hr = DispEventUnadvise( pBasicEdit );
        if( FAILED( hr ) ) 
        {
            // TODO: Handle failure condition.
        }
        return hr;
    }

    // Private member variable access functions.
    WMENC_BASICEDIT_STATE State() { return m_enumState; }

    CBasicEditCallBack() { _asm nop }
};
//============================================================

int main()
{
    // Declare variables and interfaces.
    HRESULT hr;
    IWMEncBasicEdit* pBasicEdit;
    CBasicEditCallBack BasicEvent;
    MSG msg;

    // Initialize the COM library and retrieve
    // a pointer to an IWMEncoder interface.
    hr = CoInitialize( NULL );
    hr = CoCreateInstance( CLSID_WMEncBasicEdit,
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          IID_IWMEncBasicEdit,
                          ( void** )&pBasicEdit );
    if( FAILED( hr ) ) goto EXIT;
    
    // Initialize the event sink.
    BasicEvent.Init( pBasicEdit );

    // Prepare the editing process.
    hr = pBasicEdit->put_MediaFile( L"C:\\InputFile.wmv" );
    if( FAILED( hr ) ) goto EXIT;
    hr = pBasicEdit->put_OutputFile( L"C:\\OutputFile.wmv" );
    if( FAILED( hr ) ) goto EXIT;
    hr = pBasicEdit->put_ConfigFile( L"C:\\EditConfig.xml" );
    if( FAILED( hr ) ) goto EXIT;
    hr = pBasicEdit->put_Index( VARIANT_TRUE );

    // Start the editing process.
    hr = pBasicEdit->Start();
    if( FAILED( hr ) ) goto EXIT;
    
    // Wait until the edit process stops before exiting the application.
    while( !kbhit() )
    {
        // In order for the events to be triggered correctly
        // the Windows message queue needs to be processed.
        while(PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        switch ( BasicEvent.State() )
        {
        case WMENC_ENCODER_RUNNING:
            // TODO: Handle encoder running state.
            break;

        case WMENC_ENCODER_STOPPED:
            // TODO: Handle encoder stopped state.
            goto EXIT;
        }
    }


EXIT:
    // Release the event sink.
    hr = BasicEvent.ShutDown( pBasicEdit );

    // TODO: Release temporary COM objects and uninitialize COM.
    if ( pBasicEdit )
        hr = pBasicEdit->Release();
    CoUninitialize();
    
    return hr;
}

See Also