I've been having some issues using the CameraCaptureDialog class on an HTC Apache device (rebranded as the UTstarcom 6700):
1. After exiting my application, the device's camera capture screen comes into focus. This happens whether I dispose of the class instance or not, and the Close() method is protected, so I can't call that. Any ideas on getting rid of this lingering capture screen
2. On a seemingly random, intermittent basis, an InvalidOperationException will be thrown from within the ShowDialog() method. Sometimes this will happen after taking 4 or 5 photos, but other times it will work fine for 40 or 50 photos before I give up trying to get the exception to occur again. Any thoughts on what might be causing this My only guess has been a problem with memory, but shouldn't that result in an OutOfMemoryException Also, the device seems to have plenty of memory left over when the InvalidOperationException occurs. What else could it be though An interesting observation about these exceptions is that once they occur, they tend to occur on every call thereafter. However, if I say switch to the today screen, then re-activate my application, the calls to ShowDialog() will succeed again.
3. I can't find a way to list available resolutions. Does anybody have any ideas on how to work around this besides providing a dialog in which the user is responsible for picking the resolution This worries me, because it's not documented as to what will happen if I try to use an unsupported resolution.
4. Are there any best practices for re-using instances of the CameraCaptureDialog class Should I dispose of the instance every time I take a photo I tried that method, but the device soon ran out of memory. Apparently the garbage collection wasn't doing a good job, or the CameraCaptureDialog class itself isn't well behaved. Currently, I have made a singleton wrapper class around the CameraCaptureDialog class so that I only ever have one instance in use.
Is anyone else experiencing problems using this CameraCaptureDialog class It seems to me that either some important documentation is missing, or the class itself is not ready for prime time.
Adrien.

CameraCaptureDialog Issues
Serpen
Here's a code fragment :
CameraCaptureDialog cam = new CameraCaptureDialog();
result = (DialogResult.OK == cam.ShowDialog()) PhotoResult.Ok : PhotoResult.Cancelled;
//close lingering camera dialog
SendMessage(WinAPI.FindWindow(null, cam.Title), WM_CLOSE, 0, 0);
cam.Dispose();
return result;
[DllImport("coredll.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
Derek T
How do you use this code I'm very interesting by closing the windows of the camera after i have called cameracapturedialog...
I try to simulate a key like back to close it but it doesn't work.
mroctober
Thank-you for your reply. I agree with you on the virtues of the CameraCaptureDialog. It is sure easy to get working initially, but after that it leaves a lot to be desired.
Anyways, regarding some of the points you brought up:
My photos are created using internal storage at first. If the main record is saved though, I store them in a database which is located on a mini SD card.
No, I am not forcing garbage collection. Most of the documentation I've seen states that forcing garbage collection is generally a "bad thing". My application is quite resource intensive though, and I've been considering whether this may be a practical necessity.
I have been able to reduce some of the problems which I'd been experiencing with InvalidOperationException exceptions. I provide a photo browser, with left and right arrows to switch between the photos for a product. The user can select a photo, delete it, modify it, or just add a new photo. In any event, to assign the Image property of the PictureBox, I'd been using code like this:
pboxPhoto.Image = new Bitmap(strPhotoPath);
Now, when switching to a different photo, the Bitmap created previously will become a dangling reference. I had assumed that C#'s garbage collection would take care of this, but that is apparently not the case. Actually, I suspect that the garbage collection does in fact reclaim the memory, but with too many allocations/deallocations of these large Bitmap objects, perhaps the memory gets fragmented. I have worked around this problem by keeping a reference to the Bitmap object I'm using, then Dispose() of it before creating the next one.
I've experimented a bit with those registry settings, without much effect. It almost seems as if the HTC camera doesn't even read those settings. If I change something on the device, nothing seems to change in the registry, and vice versa. Have you had any luck with these settings on other devices
Adrien.
biswajitdash
Just ran across your thread while looking for something else.
Here is what worked for me to close the "lingering" dialog:
extern
"C" __declspec(dllexport)void
closeCameraApp() {HWND cameraHandle = FindWindow(L
"WCE_IA_Camera_Main", NULL); if (cameraHandle!=NULL)SendMessage(cameraHandle, WM_CLOSE, NULL, NULL);
}
Just P/Invoke it.
Regards,
Matthew Fleming
DermVision
solrac
I'm afraid that I'm still stuck with the camera capture dialog appearing after exiting my application. I'd like to get rid of it, but I've come to the conclusion that it's out of my control. It's not even clear whether it's by design on behalf of HTC, or a bug in their code.
I doubt that you can prevent the user from changing resolutions by any normal means. There doesn't appear to be any functionality for that within the API, and once you invoke the camera capture dialog, the dialog is running the show.
While the CameraCaptureDialog functionality is really simple to get working, it lacks in documentation and advanced features. It's unfortunate, but in a sense, I think these issues are the price we pay for the simplicity.
Adrien.
Raschmann
Frank_D
as far as I've seen, yes. The multimedia API has been a big marketing point for Microsoft, and that API includes the CameraCaptureDialog.
Are you specifying any dialog parameters before showing it Or are you getting errors on instantiation of the object itself
Santiago C.
Ive had all sorts of fun with the CameraCaptureDialog, currently working with an ETen device and any attempt to use it results in an "unknown error" as soon as a I do cameraCapture.ShowDialog()
Do all WinMob5 devices actually implement the dialog
gennaro ingenito
Adrien,
1- I'm using the SHCameraCapture (Native) on a UT Starcom 6700 and I also see the camera capture screen when I close my application. My program is not a dotnet project. Did you find anything about that
3- Furter more, I would like to be able to forbid the user from selecting a different reselution than the one I passed to SHCameraCapture. Any clues
Thanks
Ausiair
Hello Andrew,
I just got a Treo 700w and I am interested in using the CameraCaptureDialog with it. I am trying to activate it with the ShowDialog command and throws an invalid argument exception. I've used the same code on HTC PPCs and it works ok.
Any ideas Would you be willing to post a code sample showing how the Treo 700W camera works with the CameraCaptureDialog
Thanks!
anca_paula
If you really want to lock resolutions down, remove the options in the registry, leaving only the resolution you desire. However, be aware you may need to experiment to find the proper location of these resolutions, there exist legacy, OEM and etc. varieties of registry keys and sometimes their effectiveness is mixed between these locations.
Also, the only way I've found to get rid of the post-app Camera.exe is to kill the process, even if the original app closes everything as cleanly as possible.
Definitely agree on your assessment, Adrien.
jnelsonjr
2. I've never received that exception, despite taking thousands of photos (I'm developing devices for a security-oriented system) ... are you storing to an SD card or internal storage (I didn't have a problem with either, but I'd be curious what your scenario is.)
3. Unsupported resolutions, in my experience, throw an exception and terminate the app. However, I haven't tried an unsupported still resolution in a while; most of my issues here were with video resolution -- I couldn't for the life of me find appropriate max res for the 700w, I couldn't use MPG, I could only record video in 3GGP mode.
4. Are you forcing garbage collection And if so, are you forcing two rounds of collection, one after the other, to both mark all resources, and collect resources marked, but not disposed of, in the first sweep
IMO, CameraCaptureDialog is awesome for its simplicity, pathetic for its extensibility.
KrisJ
the Palm Treo 700w I've worked with doesn't seem to have nearly as many instances of camera stuff in the registry, and to date I haven't played much with what little is there ... that being said, I haven't looked at it again since fully cataloguing the camera rentires on the 2125/HTC Faraday.
CodingIsFun
Is this sampe work I'm trying to compile it but i have 2 errors :
error CS0103: The name 'WinAPI' does not exist in the current context
error CS0103: The name 'WM_CLOSE' does not exist in the current context
I use VS2005 and I develop an application for smartphone C600 WM5.0.