0

I have written some code that should display a video captured from a webcam in a PictureBox. I would like to record and save the displayed video in .avi format. Is there any way to do so?

The code I have tried for recording the video is:

Dim hWnd As Long

hWnd = capCreateCaptureWindow(0, ws_visible Or ws_child, 0, 0, 0, 0, tgt.hWnd, 0)
Dim a As Boolean
a = SendMessage(hWnd, wm_cap_driver_connect, 0, 0)
a = SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0)
a = SendMessage(hWnd, WM_CAP_DLG_VIDEOCOMPRESSION, 0, 0)
a = SendMessage(hWnd, WM_CAP_FILE_SET_CAPTURE_FILE, "d:\myvideo1.avi", 0)
a = SendMessage(hWnd, WM_CAP_SET_SEQUENCE_SETUP, 96, 0)
a = SendMessage(hWnd, WM_CAP_SEQUENCE, 0, 0)

However, it gives a "Type Mismatch" error for the following line:

a = SendMessage(hWnd, WM_CAP_FILE_SET_CAPTURE_FILE, "d:\myvideo1.avi", 0)

Any ideas?

erekalper
  • 857
  • 9
  • 22
nightfire001
  • 759
  • 3
  • 20
  • 50

2 Answers2

1

Well, that and the fact that the actual unmanaged syntax requires you to specify the file name AFTER the 0 parameter i.e. you have the lParam and the wParam's mixed up.

Rob
  • 11
  • 1
0

Your API declaration for SendMessage is incompatible with String for wParam. You have to make another API declaration that can be called with strings for wParam like this

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As String, lParam As Any) As Long

then use

a = SendMessageStr(hWnd, WM_CAP_FILE_SET_CAPTURE_FILE, "d:\myvideo1.avi", 0)

on the offending line.

wqw
  • 11,771
  • 1
  • 33
  • 41
  • 1
    Now i can save my video, but when video recording is started my cursor goes to busy and i can not do other things in that form. When i click anywhere in that form, the video stops recording. Is there any way to solve this problem? – nightfire001 Jun 19 '11 at 18:25