The problem I am having is that it does not terminate the connection with the video device when the app closes and I have to reboot the computer if I launch it again.
This is the code required but it is written in C++.
Could you help me with this C++ to XOJO conversion?
This is what is in the close event of the project but it does not seem to terminate the connection with the USBwebcam.
Declare Function SendMessage lib “user32” alias “SendMessageA”(hwnd as integer,wMsg as integer,wParam as integer,lParam as integer)AS integer
DIM START AS INTEGER
DIM G AS INTEGER
START =&H400
G=START+11
CALL SendMessage(CANVAS1.Handle,G,0,0)
This is Microsoft’s recommendation https://msdn.microsoft.com/en-us/library/windows/desktop/dd756886(v=vs.85).aspx
’
'capDriverDisconnect macro
'The capDriverDisconnect macro disconnects a capture driver from a capture window. You can use this macro or explicitly send the WM_CAP_DRIVER_DISCONNECT message.
'Syntax
’
'C++
’
'BOOL capDriverDisconnect(
'hwnd
');
’
'Parameters
’
'hwnd
'Handle to a capture window.
'Return value
’
'Returns TRUE if successful or FALSE if the capture window is not connected to a capture driver.
'Requirements
’
'Minimum supported client
'Windows 2000 Professional [desktop apps only]
'Minimum supported server
'Windows 2000 Server [desktop apps only]
'Header
'Vfw.h
It looks like the Close event is passing the wrong window handle to SendMessage. Try changing CALL SendMessage(CANVAS1.Handle,G,0,0) to CALL SendMessage(cap,G,0,0).
I’ve looked at it some more and noted that there are at least two other places where CANVAS1.Handle should be replaced by cap: Pushbutton5.Action and Window1.CancelClose. Basically, there shouldn’t be any SendMessage calls that use CANVAS1.Handle as the message recipient; all SendMessage calls should all go to cap (if and only if cap<>0).
There may be more problems that are not immediately clear; the project doesn’t use named constants for window message IDs, which makes it difficult to understand what a particular SendMessage call is doing. I mean, which is clearer to you: SendMessage(cap,1034,0,0) Or SendMessage(cap,WM_CAP_DRIVER_CONNECT,0,0)?
Unfortunately, I don’t have a camera handy right now so I can’t do much testing.
Here’s an updated project file that works for me. I made everything named constants, corrected a few errors like using CANVAS1.Handle in the wrong places, and changed Window1.Close to properly release all resources.
OK, launch the app again, click on “Try to connect webcam(Click this button some more times if not connected by the first click.)”, a screen comes up requesting me to select a device, if I accept that a black screen comes up.
OK, now cover the camera with your hand and click “Take Snapshot !”, the snapshot I am getting is the one I had taken before I relaunch the app.
I don’t get this screen, when I click the button the video starts immediately. I suspect the window is generated by the camera’s driver. Do you have a different camera to try?
The camera being used is the built-in camera on the laptops, so it is 3 different cameras being used and I am getting the same response.
I do not have another camera to try now, I have one at the office.
The problem with that camera is that I have to use it with Video 2 PC and PowerDirector 9.
The problem with the camera at the office is that it shows up in the menu but if I click on it I get this message…
USB 2861 Device
Your PC ran into a problem and needs to restart. Were just collecting some error info, and then well restart for you.
If you’d like to know more, you can search online later for this error: SYSTEM SERVICE EXCEPTION (emBDA64.sys)
The same camera works with PowerDirector 9, it is a Nikon D3200
I downloaded the app and am getting the same response.
I launch the app, it launches well, I click on the connect button and it connects immediately and this canvas shows the video. I take a snapshot and that is also done correctly.
I close the app by clicking on the X at the top right of the app’s window, The app closes.
I open the app again, it opens, no picture is visible. I click on the connect button, the video section is black, and a window appears
Video source
Capture Source
A videocamera icon is there
Select a video device:
USB 2.0 VGA UVC Webcam – That is the built-in camera, no other video devices
I click on that and a menu appears with that as the only its.
I click on that
I click OK
The video screen is still black
I click “Take a snapshot”
The snapshot that I took before appears.
Clicking on the Snapshot button or Connect button does the same as above again.