How do I put the window's handle into bytes and play a video with winmm in FASM?

114 Views Asked by At

I've been trying to play a video inside of my app using winmm; I found an example for VB and translated it to FASM, but I can't figure out how to put the window's handle into the byte that I'm trying to send;

v1 db 'open 123.avi alias vid1 parent (the handle has to be here) style child',0
v2 db 'put vid1 window at 0 0 100 100',0 
v3 db 'Play vid1 notify',0
invoke mciSendString, v1, nullstring, 0, 0
invoke mciSendString, v2, nullstring, 0, 0
invoke mciSendString, v3, nullstring, 0, 0

I tried to use wprintf but to no avail; can someone please give me an example of playing a video inside the app's window?

1

There are 1 best solutions below

0
fasm14 On

Finally understood how wsprintf works! Here's a working example of a video player:

    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'