flat assembler
Message board for the users of flat assembler.

Index > Windows > Play video with winmm (get window handle)

Author
Thread Post new topic Reply to topic
fasm14



Joined: 23 Jan 2021
Posts: 14
Location: Russia
fasm14 11 Feb 2021, 06:06
Hello everyone! This might be a noob-ish question, but I how do play videos with winmm? I found this example for Visual Basic:
Code:
 mciSendString("Open " & FileName & " alias MediaFile parent " & CStr(Window.Handle.ToInt32) & " style " & CStr(WS_CHILD), Nothing, 0, 0)
mciSendString("put MediaFile window at 0 0 " & CStr(PixelToTwip(Window.ClientRectangle.Width) / 15) & " " & CStr(PixelToTwip(Window.ClientRectangle.Height) / 15), Nothing, 0, 0)
mciSendString("Close MediaFile", Nothing, 0, 0)    

...and tried to translate it to FASM, but I couldn't figure out how to append the window's handle to the bytes that I was sending; I can't even figure out how to concatenate a dword with bytes, can someone please help me with this? Without the window's handle, the video starts playing in a separate window...
Post 11 Feb 2021, 06:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20339
Location: In your JS exploiting you and your system
revolution 11 Feb 2021, 06:32
You need to convert the the handle (a dword binary number) into an ASCII decimal string.

In Windows you can use wsprintf to construct the string.
Post 11 Feb 2021, 06:32
View user's profile Send private message Visit poster's website Reply with quote
fasm14



Joined: 23 Jan 2021
Posts: 14
Location: Russia
fasm14 22 Feb 2021, 06:50
Thanks a lot! In case someone has problems with understanding wsprintf (like I did Sad), here's a small example of a video player:
Code:
format PE GUI 4.0

include 'win32a.inc'
section '.text' code readable executable
start:
    invoke  GetModuleHandle,0
    mov [wc.hInstance],eax
    invoke  LoadIcon, 0, IDI_APPLICATION
    mov [wc.hIcon], eax
    invoke  LoadCursor,0,IDC_ARROW
    mov [wc.hCursor],eax
    invoke CreateSolidBrush, 0x000000
    mov [wc.hbrBackground], eax
    invoke  RegisterClass,wc
    test    eax,eax
    jz  error
    invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,640,480,NULL,NULL,[wc.hInstance],NULL
    mov [hwnd],eax
    test    eax,eax
    jz  error



    invoke  wsprintf,str_buffer,str_format,[hwnd]
    invoke  mciSendString, str_buffer, 0
    invoke  mciSendString, str_put, 0
    invoke  mciSendString, str_play, 0


msg_loop:
    invoke  GetMessage,msg,NULL,0,0
    cmp eax,1
    jb  end_loop
    jne msg_loop
    invoke  TranslateMessage,msg
    invoke  DispatchMessage,msg
    jmp msg_loop

error:
    invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK

end_loop:
    invoke  ExitProcess,[msg.wParam]


proc WindowProc uses ebx esi edi ecx, hwnd,wmsg,wparam,lparam
    cmp [wmsg], WM_DESTROY
    je  .wmdestroy

.defwndproc:
    invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
    jmp .finish

.wmdestroy:
    invoke  PostQuitMessage,0
    xor eax,eax
    jmp .finish

.finish:
    ret
endp


section '.data' data readable writeable


str_format  db  "open intro.wmv alias video parent %d style child",0
str_buffer  db  256 dup (0)
str_play db "play video notify",0
str_put db 'put video window at 0 0 0 0',0
hwnd dd ?

_class TCHAR 'FASMWIN32',0
_title TCHAR 'Video',0
_error TCHAR 'Error',0

msg MSG

wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BACKGROUND,NULL,_class
  import  winmm,\
         mciSendString, 'mciSendStringA'


   section '.idata' import data readable writeable

     library kernel32,'KERNEL32.DLL',\
             user32,'USER32.DLL',\
             gdi32,'GDI32.DLL',\
             advapi32,'ADVAPI32.DLL',\
             comctl32,'COMCTL32.DLL',\
             winmm,'WINMM.DLL',\
             comdlg32,'COMDLG32.DLL',\
             shell32,'SHELL32.DLL',\
             wsock32,'WSOCK32.DLL'

     include 'api/kernel32.inc'
include 'api/user32.inc'
include 'api/gdi32.inc'
include 'api/advapi32.inc'
include 'api/comctl32.inc'
include 'api/comdlg32.inc'
include 'api/shell32.inc'
include 'api/wsock32.inc'    
Post 22 Feb 2021, 06:50
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.