Why capGetStatus & capDriverGetCaps doesn't work?

H

Henry Wu

Hi, I've semi-successfully converted my old VB6 project to VB.NET2003
http://wuhenry.beigetower.org/vbVideoInspection.rar ,it is a simple
webcam program that works flawlessly on VB6. Now I'm having
difficulties with the capGetStatus & capDriverGetCaps function to
work, all of the capGetStatus's & capDriverGetCaps' properites ends up
zero! Thus leaving some of my IF statements non-working.

The capGetStatus "Gets the capabilities of the capture driver" while
the capDriverGetCaps "Gets the capture window attributes .. width and
height".

Anyone working on the avicap32.dll to preview videos on their webcam
or any capture card? It'll really be great if I can get this two
functions to work. I've searched the internet for samples, I saw some
that are .NET converted, but they never did use the capGetStatus &
capDriverGetCaps.

The link above is my VB.NET project, with the AVICAP code of E. J.
Bantz Jr., modified to work on the .NET framework......w/ capGetStatus
& capDriverGetCaps NOT working. Video preview on webcam is working.

Thanks,
Henry
 
A

Armin Zingler

Henry Wu said:
Hi, I've semi-successfully converted my old VB6 project to
VB.NET2003 http://wuhenry.beigetower.org/vbVideoInspection.rar

Maybe you'll get an answer if you provide it as Zip file, (I can't extract
rar's) or the uncompressed file.
,it is
a simple webcam program that works flawlessly on VB6. Now I'm
having difficulties with the capGetStatus & capDriverGetCaps function
to work, all of the capGetStatus's & capDriverGetCaps' properites
ends up zero! Thus leaving some of my IF statements non-working.

Did you upgrade the code using the wizard or did you copy&paste the source
code?

What's your declaration of both functions?


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
S

Supra

i modifed from vb6 to vb.net. i already done in vb6 with fully loaded
that i modified. i really loved it
i never had problem.
Function capGetStatus(ByVal lwnd As Integer, ByVal s As Integer, ByVal
wSize As Short) As Boolean
capGetStatus = SendMessage(lwnd, WM_CAP_GET_STATUS, wSize, s)
End Function
Function capDriverGetCaps(ByVal lwnd As Integer, ByVal s As Integer,
ByVal wSize As Short) As Boolean
'The capDriverGetCaps macro returns the hardware capabilities of the
capture driver currently connected to a capture window.
capDriverGetCaps = SendMessage(lwnd, WM_CAP_DRIVER_GET_CAPS, wSize, s)
End Function

above is vfw i had now error problem.
right now i have 5 error problems so far i will do it later. i have read
ur posted stating that u wanted mnuvideofrm to child or mdiparent. but
u can't changed it becaue if that it is constant.
Public Const WS_CHILD As Integer = &H40000000
if u removed it u will get parent but not child.
in ur case u can remove const to dim or private and if not betst way to
do is property get/set procedure events.
i am working on. but i have to fixed errors problem first.
i can help u.
regards
 
H

Henry Wu

Maybe you'll get an answer if you provide it as Zip file
Hi here's the Zip file link:
http://wuhenry.beigetower.org/vbVideoInspection.zip
Did you upgrade the code using the wizard or did you copy&paste the source
code?
I did not use the .NET wizard to upgrade my code, I did it again from
scratch since I wanted to learn .NET from scratch too :)
What's your declaration of both functions?

capDriverGetCaps declaration:
---------------------------------

Public Function capDriverGetCaps(ByVal lwnd As Integer, ByVal s As
Integer, ByVal wSize As Short) As Boolean
capDriverGetCaps = SendMessage(lwnd, WM_CAP_DRIVER_GET_CAPS,
wSize, s)
End Function
---------------------------------


capDriverGetCaps usage:
---------------------------------
capDriverGetCaps(lwndC, VarPtrAny(Caps), Len(Caps))

Debug.WriteLine(Caps.wDeviceIndex & "-wDeviceIndex")
Debug.WriteLine(Caps.fHasOverlay & "-fHasOverlay")
Debug.WriteLine(Caps.fHasDlgVideoSource &
"-fHasDlgVideoSource")
Debug.WriteLine(Caps.fHasDlgVideoFormat &
"-fHasDlgVideoFormat")
Debug.WriteLine(Caps.fHasDlgVideoDisplay &
"-fHasDlgVideoDisplay")
Debug.WriteLine(Caps.fCaptureInitialized &
"-fCaptureInitialized")
Debug.WriteLine(Caps.fDriverSuppliesPalettes &
"-fDriverSuppliesPalettes")
Debug.WriteLine(Caps.hVideoIn & "-hVideoIn")
Debug.WriteLine(Caps.hVideoOut & "-hVideoOut")
Debug.WriteLine(Caps.hVideoExtIn & "-hVideoExtIn")
Debug.WriteLine(Caps.hVideoExtOut & "-hVideoExtOut")
Debug.WriteLine(CInt(False) & "-False")
Debug.WriteLine(CInt(True) & "-True")
---------------------------------

Using VarPtrAny as:
---------------------------------
Public Function VarPtrAny(ByVal o As Object) As Integer
Dim GC As System.Runtime.InteropServices.GCHandle =
System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned)
Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return ret
End Function
---------------------------------

capGetStatus declaration
---------------------------------
Public Function capGetStatus(ByVal lwnd As Integer, ByVal s As
Integer, ByVal wSize As Short) As Boolean
capGetStatus = SendMessage(lwnd, WM_CAP_GET_STATUS, wSize, s)
End Function
---------------------------------

capGetStatus usage
---------------------------------
Dim CAPSTATUS As CAPSTATUS
Dim ImageWidth As Integer
Dim ImageHeight As Integer

If capGetStatus(lwnd, VarPtrAny(CAPSTATUS), Len(CAPSTATUS)) Then
'//Set title of the parent form
ImageWidth = CAPSTATUS.uiImageWidth
ImageHeight = CAPSTATUS.uiImageHeight
SetWindowText(frmVideoPreviewGlobal.Handle.ToInt32, "Video
Preview: " & CAPSTATUS.uiImageWidth & "x" & CAPSTATUS.uiImageHeight &
" Resolution")
End If
---------------------------------


capDriverGetCaps always renders 0 or False, even if I see a streaming
video preview. And also capGetStatus doesn't work either because
CAPSTATUS.uiImageWidth & CAPSTATUS.uiImageHeight renders "Video
Preview: 0x0 Resolution", but again, I have a nice clean video stream
of 640x480 or 320x240 or whatever video format I set my webcam to.

Hoping for some help, I'm really stuck, it's a bit hard to find the
culprit w/o any errors showing up :(

Thanks,
Henry
 
H

Henry Wu

Hi!

I believe we have the same declarations on both functions. That's so
weird, you said yours is working? I wonder why mine doesn't? Below is
my Form Load code, my problem is that all of the capDriverGetCaps
values turns out Zero or False, I use Debug.WriteLine to test them all
out.

Thanks,
Henry



Private Sub frmVideoPreview_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

Dim FormBorderStyle As Long
Dim lpszName As String = Space(100)
Dim lpszVer As String = Space(100)
Dim Caps As CAPDRIVERCAPS



'//Create Capture Window
capGetDriverDescriptionA(0, lpszName, 100, lpszVer, 100)

'// Retrieves driver info
lwndC = capCreateCaptureWindowA(lpszName, WS_VISIBLE Or
WS_CHILD, 0, 0, DefaultWidth, DefaultHeight,
Me.PictureBox1.Handle.ToInt32, 0)

'// Set driver name to status bar
Me.stbVideoPreview.Text = "Video Driver: " & lpszName

'// Set the video stream callback function
capSetCallbackOnStatusDelegate(lwndC, AddressOf
MyStatusCallback)
capSetCallbackOnErrorDelegate(lwndC, AddressOf
MyErrorCallback)

'// Connect the capture window to the driver
If capDriverConnect(lwndC, 0) Then
'/////
'// Only do the following if the connect was successful.
'// if it fails, the error will be reported in the call
'// back function.
'/////

'// Get the capabilities of the capture driver
capDriverGetCaps(lwndC, VarPtrAny(Caps), Len(Caps))

Debug.WriteLine(Caps.wDeviceIndex & "-wDeviceIndex")
Debug.WriteLine(Caps.fHasOverlay & "-fHasOverlay")
Debug.WriteLine(Caps.fHasDlgVideoSource &
"-fHasDlgVideoSource")
Debug.WriteLine(Caps.fHasDlgVideoFormat &
"-fHasDlgVideoFormat")
Debug.WriteLine(Caps.fHasDlgVideoDisplay &
"-fHasDlgVideoDisplay")
Debug.WriteLine(Caps.fCaptureInitialized &
"-fCaptureInitialized")
Debug.WriteLine(Caps.fDriverSuppliesPalettes &
"-fDriverSuppliesPalettes")
Debug.WriteLine(Caps.hVideoIn & "-hVideoIn")
Debug.WriteLine(Caps.hVideoOut & "-hVideoOut")
Debug.WriteLine(Caps.hVideoExtIn & "-hVideoExtIn")
Debug.WriteLine(Caps.hVideoExtOut & "-hVideoExtOut")
Debug.WriteLine(CInt(False) & "-False")
Debug.WriteLine(CInt(True) & "-True")

'// Stretch preview video always
capPreviewScale(lwndC, True)

'// Set the preview rate in milliseconds
capPreviewRate(lwndC, 66)

'// Start previewing the image from the camera
capPreview(lwndC, True)

End If

End Sub
 
S

Supra

i have problem about variable not declare: i don't what variables is this.

'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click
for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1016"'
Private Declare Function SendMessageAsAny Lib "user32" Alias
"SendMessageA"(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal
wParam As Integer, ByRef lParam As Any) As Integer


'UPGRADE_ISSUE: StrPtr function is not supported. Click for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1040"'
lStrCpy(StrPtr(sStatusText), ipstrStatusText) '// Copy message into String


'UPGRADE_ISSUE: Constant vbUnicode was not upgraded. Click for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2070"'
usStatusText = StrConv(sStatusText, vbUnicode)

i will do from scratch because i'm using GDI. i will not be using controls.
regards,
 
S

Supra

never mind. the vb.net has changed. so i don't see 2 api calls @ same
time, so i have to used rem
thank to vb.net.
regards,
 
H

Henry Wu

'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click
for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1016"'
Private Declare Function SendMessageAsAny Lib "user32" Alias
"SendMessageA"(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal
wParam As Integer, ByRef lParam As Any) As Integer

Change "ByRef lParam As Any" To "ByRef lParam As Object"

'UPGRADE_ISSUE: StrPtr function is not supported. Click for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1040"'
lStrCpy(StrPtr(sStatusText), ipstrStatusText) '// Copy message >into String

Use the following code for all VarPtr & StrPtr.
So, the function "lStrCpy(StrPtr(sStatusText), ipstrStatusText)" will
be "lStrCpy(VarPtrAny(sStatusText), ipstrStatusText)"

-------------------------------------------------------------
Public Function VarPtrAny(ByVal o As Object) As Integer
Dim GC As System.Runtime.InteropServices.GCHandle =
System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned)
Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return ret
End Function
-------------------------------------------------------------
'UPGRADE_ISSUE: Constant vbUnicode was not upgraded. Click for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2070"'
usStatusText = StrConv(sStatusText, vbUnicode)

VB.NET is already in Unicode, no conversions is necessary.
So "usStatusText = StrConv(sStatusText, vbUnicode)" should just be
"usStatusText = sStatusText"


Hope this helps.
Henry

If anyone's able to duplicate or replicate my problem, I'll be relieve
and hopefully someone has a solution for it :) , I'm still scratching
head here :)

Thanks again,
Henry
 
S

Supra

thank. it works now.
regards,

Henry said:
Change "ByRef lParam As Any" To "ByRef lParam As Object"





Use the following code for all VarPtr & StrPtr.
So, the function "lStrCpy(StrPtr(sStatusText), ipstrStatusText)" will
be "lStrCpy(VarPtrAny(sStatusText), ipstrStatusText)"

-------------------------------------------------------------
Public Function VarPtrAny(ByVal o As Object) As Integer
Dim GC As System.Runtime.InteropServices.GCHandle =
System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned)
Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return ret
End Function
-------------------------------------------------------------




VB.NET is already in Unicode, no conversions is necessary.
So "usStatusText = StrConv(sStatusText, vbUnicode)" should just be
"usStatusText = sStatusText"


Hope this helps.
Henry

If anyone's able to duplicate or replicate my problem, I'll be relieve
and hopefully someone has a solution for it :) , I'm still scratching
head here :)

Thanks again,
Henry
 
H

Henry Wu

Supra, Armin,

any news on how to get the current video's width & height? ex: 320x240

and also on how to get if the current capture device has video source
dialog box, video format dialog box, etc.?

all in VB.NET.

Still stuck,
Henry
 
K

Ken Tucker [MVP]

Hi,

Declare sendmessage as shown. Use it as below. You can have multiple
versions of sendmessage.

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

Dim bReturn As Boolean
Dim wSize As Integer
Dim s As CAPSTATUS
bReturn = SendMessage(hHwnd, WM_CAP_GET_STATUS,
Marshal.SizeOf(s), s)
Debug.WriteLine(String.Format("Video Size {0} x {1}",
s.uiImageWidth, s.uiImageHeight))

Here is a link to an example.
http://www.onteorasoftware.com/downloads/webcam.zip


Ken
-----------------
 
H

Henry Wu

Thanks Ken Tucker!!!

I'll be ending my posted question here by typing down the functions
that worked for me.


======================================================================


Place in a Module
--------------------------------

Public capstatusC As CAPSTATUS
Public capdrivercapsC As CAPDRIVERCAPS

Public Declare Function SendMessageC Lib "user32" Alias
"SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal
wParam As Integer, ByRef lParam As CAPSTATUS) As Boolean

Public Declare Function SendMessageC Lib "user32" Alias
"SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal
wParam As Integer, ByRef lParam As CAPDRIVERCAPS) As Boolean


'------------------------------------------
Public Function capDriverGetCaps(ByVal lwnd As Integer) As Boolean
Dim s As CAPDRIVERCAPS
capDriverGetCaps = SendMessageC(lwnd, WM_CAP_DRIVER_GET_CAPS,
System.Runtime.InteropServices.Marshal.SizeOf(s), s)
If capDriverGetCaps = True Then capdrivercapsC = s
End Function
'------------------------------------------

'------------------------------------------
Public Function capGetStatus(ByVal lwnd As Integer) As Boolean
Dim s As CAPSTATUS
capGetStatus = SendMessageC(lwnd, WM_CAP_GET_STATUS,
System.Runtime.InteropServices.Marshal.SizeOf(s), s)
If capGetStatus = True Then capstatusC = s
End Function
'------------------------------------------

======================================================================

capDriverGetCaps TEST
--------------------------------------------

If capDriverConnect(lwndC, 0) Then
capDriverGetCaps(lwndC)
Debug.WriteLine(capdrivercapsC.wDeviceIndex &
"-wDeviceIndex")
Debug.WriteLine(capdrivercapsC.fHasOverlay &
"-fHasOverlay")
Debug.WriteLine(capdrivercapsC.fHasDlgVideoSource &
"-fHasDlgVideoSource")
Debug.WriteLine(capdrivercapsC.fHasDlgVideoFormat &
"-fHasDlgVideoFormat")
Debug.WriteLine(capdrivercapsC.fHasDlgVideoDisplay &
"-fHasDlgVideoDisplay")
Debug.WriteLine(capdrivercapsC.fCaptureInitialized &
"-fCaptureInitialized")
Debug.WriteLine(capdrivercapsC.fDriverSuppliesPalettes &
"-fDriverSuppliesPalettes")
Debug.WriteLine(capdrivercapsC.hVideoIn & "-hVideoIn")
Debug.WriteLine(capdrivercapsC.hVideoOut & "-hVideoOut")
Debug.WriteLine(capdrivercapsC.hVideoExtIn &
"-hVideoExtIn")
Debug.WriteLine(capdrivercapsC.hVideoExtOut &
"-hVideoExtOut")
Debug.WriteLine(CInt(False) & "-False")
Debug.WriteLine(CInt(True) & "-True")
End If
--------------------------------------------


capGetStatus TEST
--------------------------------------------
If capGetStatus(lwnd) = True Then
Debug.WriteLine(String.Format("Video Size {0} x {1}",
capstatusC.uiImageWidth, capstatusC.uiImageHeight))
--------------------------------------------

======================================================================



Thanks again Ken Tucker for the solution!!!


I wonder why the original functions (below) wont work?
--------------------------------------------
Public Function capDriverGetCaps(ByVal lwnd As Integer, ByVal s As
Integer, ByVal wSize As Short) As Boolean
capDriverGetCaps = SendMessage(lwnd, WM_CAP_DRIVER_GET_CAPS,
wSize, s)
End Function

Public Function capGetStatus(ByVal lwnd As Integer, ByVal s As
Integer, ByVal wSize As Short) As Boolean
capGetStatus = SendMessage(lwnd, WM_CAP_GET_STATUS, wSize, s)
End Function
--------------------------------------------



Calling them like so:
--------------------------------------------
capDriverGetCaps(lwndC, VarPtr(Caps), Len(Caps))
capGetStatus(lwnd, VarPtr(CAPSTATUS), Len(CAPSTATUS))



While using VarPtr as:
--------------------------------------------
Public Function VarPtr(ByVal o As Object) As Integer
Dim GC As System.Runtime.InteropServices.GCHandle =
System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned)
Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return ret
End Function
--------------------------------------------


Both of them uses VarPtr, maybe that's the culprit??
Well, it works now, but it'll be a great added knowledge to know what
went wrong.

Henry
 
O

Oakking1

Henry said:
*Thanks Ken Tucker!!!

I'll be ending my posted question here by typing down the functions
that worked for me.


======================================================================


Place in a Module
--------------------------------

Public capstatusC As CAPSTATUS
Public capdrivercapsC As CAPDRIVERCAPS

Public Declare Function SendMessageC Lib "user32" Alias
"SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal
wParam As Integer, ByRef lParam As CAPSTATUS) As Boolean

Public Declare Function SendMessageC Lib "user32" Alias
"SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal
wParam As Integer, ByRef lParam As CAPDRIVERCAPS) As Boolean


'------------------------------------------
Public Function capDriverGetCaps(ByVal lwnd As Integer) As Boolean
Dim s As CAPDRIVERCAPS
capDriverGetCaps = SendMessageC(lwnd, WM_CAP_DRIVER_GET_CAPS,
System.Runtime.InteropServices.Marshal.SizeOf(s), s)
If capDriverGetCaps = True Then capdrivercapsC = s
End Function
'------------------------------------------

'------------------------------------------
Public Function capGetStatus(ByVal lwnd As Integer) As Boolean
Dim s As CAPSTATUS
capGetStatus = SendMessageC(lwnd, WM_CAP_GET_STATUS,
System.Runtime.InteropServices.Marshal.SizeOf(s), s)
If capGetStatus = True Then capstatusC = s
End Function
'------------------------------------------

======================================================================

capDriverGetCaps TEST
--------------------------------------------

If capDriverConnect(lwndC, 0) Then
capDriverGetCaps(lwndC)
Debug.WriteLine(capdrivercapsC.wDeviceIndex &
"-wDeviceIndex")
Debug.WriteLine(capdrivercapsC.fHasOverlay &
"-fHasOverlay")
Debug.WriteLine(capdrivercapsC.fHasDlgVideoSource &
"-fHasDlgVideoSource")
Debug.WriteLine(capdrivercapsC.fHasDlgVideoFormat &
"-fHasDlgVideoFormat")
Debug.WriteLine(capdrivercapsC.fHasDlgVideoDisplay &
"-fHasDlgVideoDisplay")
Debug.WriteLine(capdrivercapsC.fCaptureInitialized &
"-fCaptureInitialized")
Debug.WriteLine(capdrivercapsC.fDriverSuppliesPalettes &
"-fDriverSuppliesPalettes")
Debug.WriteLine(capdrivercapsC.hVideoIn & "-hVideoIn")
Debug.WriteLine(capdrivercapsC.hVideoOut & "-hVideoOut")
Debug.WriteLine(capdrivercapsC.hVideoExtIn &
"-hVideoExtIn")
Debug.WriteLine(capdrivercapsC.hVideoExtOut &
"-hVideoExtOut")
Debug.WriteLine(CInt(False) & "-False")
Debug.WriteLine(CInt(True) & "-True")
End If
--------------------------------------------


capGetStatus TEST
--------------------------------------------
If capGetStatus(lwnd) = True Then
Debug.WriteLine(String.Format("Video Size {0} x {1}",
capstatusC.uiImageWidth, capstatusC.uiImageHeight))
--------------------------------------------

======================================================================



Thanks again Ken Tucker for the solution!!!


I wonder why the original functions (below) wont work?
--------------------------------------------
Public Function capDriverGetCaps(ByVal lwnd As Integer, ByVal s As
Integer, ByVal wSize As Short) As Boolean
capDriverGetCaps = SendMessage(lwnd, WM_CAP_DRIVER_GET_CAPS,
wSize, s)
End Function

Public Function capGetStatus(ByVal lwnd As Integer, ByVal s As
Integer, ByVal wSize As Short) As Boolean
capGetStatus = SendMessage(lwnd, WM_CAP_GET_STATUS, wSize, s)
End Function
--------------------------------------------



Calling them like so:
--------------------------------------------
capDriverGetCaps(lwndC, VarPtr(Caps), Len(Caps))
capGetStatus(lwnd, VarPtr(CAPSTATUS), Len(CAPSTATUS))



While using VarPtr as:
--------------------------------------------
Public Function VarPtr(ByVal o As Object) As Integer
Dim GC As System.Runtime.InteropServices.GCHandle =
System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned)
Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return ret
End Function
--------------------------------------------


Both of them uses VarPtr, maybe that's the culprit??
Well, it works now, but it'll be a great added knowledge to know
what
went wrong.

Henry *


Henry,

You wouldn't happen to have an idea on how to save the preview to an
AVI or some other video file.

Thanks,
Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top