.586 .model flat,stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\kernel32.inc include \masm32\include\user32.inc include \masm32\include\comdlg32.inc include \masm32\include\ole32.inc includelib \masm32\lib\kernel32.lib includelib \masm32\lib\user32.lib includelib \masm32\lib\comdlg32.lib includelib \masm32\lib\ole32.lib ; My own crazy definitions OPENFILENAMEW STRUCT lStructSize DWORD ? hwndOwner DWORD ? hInstance DWORD ? lpstrFilter DWORD ? lpstrCustomFilter DWORD ? nMaxCustFilter DWORD ? nFilterIndex DWORD ? lpstrFile DWORD ? nMaxFile DWORD ? lpstrFileTitle DWORD ? nMaxFileTitle DWORD ? lpstrInitialDir DWORD ? lpstrTitle DWORD ? Flags DWORD ? nFileOffset WORD ? nFileExtension WORD ? lpstrDefExt DWORD ? lCustData DWORD ? lpfnHook DWORD ? lpTemplateName DWORD ? OPENFILENAMEW ENDS GetOpenFileNameW PROTO :DWORD include \masm32\com\include\oaidl.inc ; IGraphBuilder Interface IGraphBuilder STRUCT DWORD IGraphBuilder_QueryInterface comethod3 ? IGraphBuilder_AddRef comethod1 ? IGraphBuilder_Release comethod1 ? IGraphBuilder_AddFilter comethod3 ? IGraphBuilder_RemoveFilter comethod2 ? IGraphBuilder_EnumFilters comethod2 ? IGraphBuilder_FindFilterByName comethod3 ? IGraphBuilder_ConnectDirect comethod4 ? IGraphBuilder_Reconnect comethod2 ? IGraphBuilder_Disconnect comethod2 ? IGraphBuilder_SetDefaultSyncSource comethod1 ? IGraphBuilder_Connect comethod3 ? IGraphBuilder_Render comethod2 ? IGraphBuilder_RenderFile comethod3 ? IGraphBuilder_AddSourceFilter comethod4 ? IGraphBuilder_SetLogFile comethod2 ? IGraphBuilder_Abort comethod1 ? IGraphBuilder_ShouldOperationContinue comethod1 ? IGraphBuilder ENDS IMediaControl STRUCT DWORD IMediaControl_QueryInterface comethod3 ? IMediaControl_AddRef comethod1 ? IMediaControl_Release comethod1 ? IMediaControl_GetTypeInfoCount comethod2 ? IMediaControl_GetTypeInfo comethod4 ? IMediaControl_GetIDsOfNames comethod6 ? IMediaControl_Invoke comethod9 ? IMediaControl_Run comethod1 ? IMediaControl_Pause comethod1 ? IMediaControl_Stop comethod1 ? IMediaControl_GetState comethod3 ? IMediaControl_RenderFile comethod2 ? IMediaControl_AddSourceFilter comethod3 ? IMediaControl_get_FilterCollection comethod2 ? IMediaControl_get_RegFilterCollection comethod2 ? IMediaControl_StopWhenReady comethod1 ? IMediaControl ENDS IMediaEvent STRUCT DWORD IMediaEvent_QueryInterface comethod3 ? IMediaEvent_AddRef comethod1 ? IMediaEvent_Release comethod1 ? IMediaEvent_GetTypeInfoCount comethod2 ? IMediaEvent_GetTypeInfo comethod4 ? IMediaEvent_GetIDsOfNames comethod6 ? IMediaEvent_Invoke comethod9 ? IMediaEvent_GetEventHandle comethod2 ? IMediaEvent_GetEvent comethod5 ? IMediaEvent_WaitForCompletion comethod3 ? IMediaEvent_CancelDefaultHandling comethod2 ? IMediaEvent_RestoreDefaultHandling comethod2 ? IMediaEvent_FreeEventParams comethod4 ? IMediaEvent ENDS .const CLSID_FilterGraph GUID {0e436ebb3H, 524fH, 11ceH, \ {9fH, 53H, 00H, 20H, 0afH, 0bH, 0a7H, 70H} } IID_IGraphBuilder GUID {56a868a9H, 0ad4H, 11ceH, \ {0b0H, 3aH, 00H, 20H, 0afH, 0bH, 0a7H, 70H} } IID_IMediaControl GUID {56a868b1H, 0ad4H, 11ceH, \ {0b0H, 3aH, 00H, 20H, 0afH, 0bH, 0a7H, 70H} } IID_IMediaEvent GUID {56a868b6H, 0ad4H, 11ceH, \ {0b0H, 3aH, 00H, 20H, 0afH, 0bH, 0a7H, 70H} } ;;;;;;; USE ORDINAL IMPORTS!!! .code public start start PROC ; Local variables LOCAL ofn: OPENFILENAMEW LOCAL filename[256]: WORD LOCAL pGraphBuilder: DWORD LOCAL pMediaControl: DWORD LOCAL pMediaEvent: DWORD LOCAL event: HANDLE LOCAL media_event: DWORD LOCAL media_param1: DWORD LOCAL media_param2: DWORD LOCAL msg: MSG ; Get file name xor eax,eax mov word ptr [filename],ax lea edi,ofn push edi mov ecx,((SIZEOF ofn)/4) rep stosd mov ofn.lStructSize,SIZEOF ofn mov ofn.nMaxFile,256 lea edx,filename mov ofn.lpstrFile,edx mov ofn.Flags,(OFN_EXPLORER or OFN_FILEMUSTEXIST or OFN_HIDEREADONLY or OFN_PATHMUSTEXIST) call GetOpenFileNameW test eax,eax jz exit0 ; Initialize COM and DirectShow INVOKE CoInitialize,0 test eax,eax ; SUCCEEDED(hr) js exit1 ; Create FilterGraph object and get interfaces INVOKE CoCreateInstance,ADDR CLSID_FilterGraph,0,CLSCTX_INPROC, ADDR IID_IGraphBuilder, ADDR pGraphBuilder test eax,eax js exit1 ; ecx=GraphBuilder, edx=GraphBuilderVTable mov ebx,pGraphBuilder mov edi,[ebx] mov esi,(IGraphBuilder PTR [edi]).IGraphBuilder_QueryInterface ; pGraphBuiler->QueryInterface(IID_IMediaControl) lea eax,pMediaControl push eax push OFFSET IID_IMediaControl push ebx call esi test eax,eax js exit1 ; pGraphBuiler->QueryInterface(IID_IMediaEvent) lea eax,pMediaEvent push eax push OFFSET IID_IMediaEvent push ebx call esi test eax,eax js exit1 ; Use DirectShow to render file ; pGraphBuilder->RenderFile(filename) mov ebx,pGraphBuilder mov edi,[ebx] lea eax,filename push eax push ebx call (IGraphBuilder PTR [edi]).IGraphBuilder_RenderFile test eax,eax js exit1 ; pMediaControl->Run() mov ebx,pMediaControl mov edi,[ebx] push ebx call (IMediaControl PTR [edi]).IMediaControl_Run test eax,eax js exit1 ; pMediaEvent->GetEventHandle(&event) mov ebx,pMediaEvent mov edi,[ebx] lea eax,event push eax push ebx call (IMediaEvent PTR [edi]).IMediaEvent_GetEventHandle test eax,eax js exit1 pump: ; Message pump push QS_ALLINPUT push INFINITE push FALSE lea eax,event push eax push 1 call MsgWaitForMultipleObjects test eax,eax ; WAIT_OBJECT_0 jz pump_media_event dec eax ; WAIT_OBJECT_0+1 jz pump_message jmp pump pump_message: lea ebx,msg INVOKE PeekMessage,ebx,0,0,0,PM_REMOVE test eax,eax jz pump cmp msg.message,WM_QUIT je pump_end INVOKE TranslateMessage,ebx INVOKE DispatchMessage,ebx jmp pump_message pump_media_event: ; pMediaEvent->GetEvent() mov ebx,pMediaEvent mov edi,[ebx] INVOKE (IMediaEvent PTR [edi]).IMediaEvent_GetEvent, ebx, ADDR media_event, ADDR media_param1, ADDR media_param2, 0 test eax,eax js pump ; if(event == EC_COMPLETE/*1*/ || event == EC_USERABORT/*2*/) mov eax,media_event dec eax jz pump_media_event_quit dec eax jnz pump_media_event_free pump_media_event_quit: INVOKE PostQuitMessage,0 pump_media_event_free: ; pMediaEvent->FreeEventParams(event, param1, param2) INVOKE (IMediaEvent PTR [edi]).IMediaEvent_FreeEventParams, ebx, media_event, media_param1, media_param2 jmp pump_media_event pump_end: ; Clean up ; pMediaEvent->Release() mov eax,pMediaEvent mov edx,[eax] INVOKE (IMediaEvent PTR [edx]).IMediaEvent_Release, eax ; pMediaControl->Release() mov eax,pMediaControl mov edx,[eax] INVOKE (IMediaControl PTR [edx]).IMediaControl_Release, eax ; pGraphBuilder->Release() mov eax,pGraphBuilder mov edx,[eax] INVOKE (IGraphBuilder PTR [edx]).IGraphBuilder_Release, eax INVOKE CoUninitialize exit0: xor eax,eax INVOKE ExitProcess,eax exit1: xor eax,eax inc eax INVOKE ExitProcess,eax start ENDP end start