[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 655
  • Last Modified:

what is the meaning of following assignment in vb.net2003 windows application ?

Const WM_CAP As Short = &H400S

what is meaning of &h400s
what is the meaning of the symbol  &
what will execute   for this assignment ?
please explain as clear.
7 Solutions
Its a constant. You are defining a constant. Something like #define in C,C++. Can you tell the background of this code snippet???
&H is use for defining a variable in HEX
Khalid Mehmood AwanCommented:
May be this will help you, &H is used for hexadecimal numbers.


Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Meir RivkinFull stack Software EngineerCommented:
deinfing a constant variable named WM_CAP with value 0x400 in hex (1024 in decimal)

C# ->  const short WM_CAP = 0x400;

it is used in multimedia messages to capture video from a video device such as a webcam.

check http://www.thaiio.com/prog-cgi/vbnetwebcam.html

TamilselvanAuthor Commented:
Const WM_CAP As Short = &H400S
is this &h400s identifiy the usb port or  not  ?

Meir RivkinFull stack Software EngineerCommented:
it is just a constant to use for other WM_CAP mesages to send to the device.
chjeck the code snippet
' Create constant to use when sending messages to device

    Const WM_CAP As Short = &H400S
    Const WM_CAP_DRIVER_CONNECT As Integer = WM_CAP + 10
    Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP + 11
    Const WM_CAP_EDIT_COPY As Integer = WM_CAP + 30
    Const WM_CAP_SET_PREVIEW As Integer = WM_CAP + 50
    Const WM_CAP_SET_PREVIEWRATE As Integer = WM_CAP + 52
    Const WM_CAP_SET_SCALE As Integer = WM_CAP + 53
    Const WS_CHILD As Integer = &H40000000
    Const WS_VISIBLE As Integer = &H10000000
    Const SWP_NOMOVE As Short = &H2S
    Const SWP_NOSIZE As Short = 1
    Const SWP_NOZORDER As Short = &H4S
    Const HWND_BOTTOM As Short = 1

    Dim iDevice As Integer = 0  ' Normal device ID 
    Dim hHwnd As Integer  ' Handle value to preview window

  ' Declare function from AVI capture DLL.

    Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
        (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
         ByVal lParam As Object) As Integer

    Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, _
        ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, _
        ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer

    Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean

    Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
        (ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
        ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
        ByVal nHeight As Short, ByVal hWndParent As Integer, _
        ByVal nID As Integer) As Integer

    Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, _
        ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _
        ByVal cbVer As Integer) As Boolean

  ' Load name of all avialable devices into the lstDevices .

Private Sub LoadDeviceList()
        Dim strName As String = Space(100)
        Dim strVer As String = Space(100)
        Dim bReturn As Boolean
        Dim x As Integer = 0
Dim lstDevices as ListBox = new ListBox()

          '   Get Driver name and version
           bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)
           ' If there was a device add device name to the list 
           If bReturn Then lstDevices.Items.Add(strName.Trim)
            x += 1
        Loop Until bReturn = False
    End Sub

   ' To display the output from a video capture device, you need to create a capture window.
 Private Sub OpenPreviewWindow()
        Dim iHeight As Integer = picCapture.Height
        Dim iWidth As Integer = picCapture.Width

        ' Open Preview window in picturebox .
        ' Create a child window with capCreateCaptureWindowA so you can display it in a picturebox.

        hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, _
            480, picCapture.Handle.ToInt32, 0)

     ' Connect to device
      If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then

      ' Set the preview scale
           SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)

      ' Set the preview rate in milliseconds
          SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)

      ' Start previewing the image from the camera 
            SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)

       ' Resize window to fit in picturebox 
            SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, picCapture.Width, picCapture.Height, _
                                   SWP_NOMOVE Or SWP_NOZORDER)
            btnSave.Enabled = True
            btnStop.Enabled = True
            btnStart.Enabled = False
        ' Error connecting to device close window 
          btnSave.Enabled = False
        End If
    End Sub

 'disconnect from the device
  Private Sub ClosePreviewWindow()
       ' Disconnect from device
       SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)
   End Sub

Open in new window

Meir RivkinFull stack Software EngineerCommented:
u can see that WM_CAP is merely used as an offset of the actual messages Ids.
u could have drop WM_CAP and use the actual value of the WM_CAP_XXX:

    Const WM_CAP_DRIVER_CONNECT As Integer = 1034
    Const WM_CAP_DRIVER_DISCONNECT As Integer = 1035
    Const WM_CAP_EDIT_COPY As Integer = 1054
    Const WM_CAP_SET_PREVIEW As Integer = 1074
    Const WM_CAP_SET_PREVIEWRATE As Integer = 1076
    Const WM_CAP_SET_SCALE As Integer = 1077
TamilselvanAuthor Commented:
i dont understand. please clarify.
what does identify 1034.
is it call to function id ?
is it a driver file id number?
Meir RivkinFull stack Software EngineerCommented:
1034 is the message id sent to the device.
it's similar to any other window message in win32 api.
for example, when u click a left button on winform, in the background SendMessage() is called with WM_LBUTTONCLICK:
SendMessage( m_hWnd, WM_LBUTTONCLICK, 0, 0);  

m_hWnd is the handle of the window, WM_LBUTTONCLICK is a constant with value 0x0201 (which is 513 in decimal)
the other 2 params has different meaning for each message.

regarding WM_CAP messages, in avicap32.dll all constants are declared the same way.
so lets take one line from the code above:
SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)

SendMessage locate the target using the handle hHwnd and send the message  WM_CAP_DRIVER_DISCONNECT with 2 additional params (iDevice and 0).
somehere in avicap32.dll there's a switch which handles all WM_CAP messages, something like:

LRESULT ::WindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam )  
//connect to device

//disconnect from device


Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now