I am using this project by Frederik …
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
This is Microsoft’s recommendation
'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.
'Handle to a capture window.
'Returns TRUE if successful or FALSE if the capture window is not connected to a capture driver.
'Minimum supported client
'Windows 2000 Professional [desktop apps only]
'Minimum supported server
'Windows 2000 Server [desktop apps only]
It looks like the Close event is passing the wrong window handle to SendMessage. Try changing
CALL SendMessage(CANVAS1.Handle,G,0,0) to
It works, but after several attempts to connect.
Is there anything else that needs to be modified.
I’ve looked at it some more and noted that there are at least two other places where
CANVAS1.Handle should be replaced by
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
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:
Unfortunately, I don’t have a camera handy right now so I can’t do much testing.
Thanks for your response and suggestions.
I agree with your suggestions re SendMessage(cap,1034,0,0) Or SendMessage(cap,WM_CAP_DRIVER_CONNECT,0,0).
I have noticed the same code in CancelClose as in close, should cap be called there or CANVAS1.Handle?
Still needs several attempts to connect when the app is re-launched.
It should be cap.
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.
I tried it but when I launch it, connect, take a snapshot, close it then relaunch, it would not connect… I have to reboot.
What could be the problem there?
I don’t know what the problem might be. Connecting and taking a snapshot works for me even after closing and relaunching.
OK Andrew, Thanks,
I will try it on another PC and see what happens.
Thanks again Andrew.
OK, if yourelaunch it, that snapshot is not a new snapshot, it is the one that was taken previously.
TheCam screen is black also.
I don’t know if you are getting that too.
No, I’m not getting that.
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.
This happens on two computers here.
I will try it on a third one and see.
I am getting the same response on a third computer. I don’t have anymore to try it on.
I don’t know what to say now.
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 don’t know if this is the problem.
I am using XOJO 2015 Release 4.1 on a Mac, so I am building on a Mac and launching the app on PC.
Could you send me a copy of the built app and let me try that out?
Andrew’s code works for me on a Win7 laptop.
So what could be the problem? Could you send me a copy of the built app?
Built with RS2011r4.3 I’m also using Windows 7
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
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.
I don’t know what to say now.