free web page counters

Windows Mobile Pocket PC Smartphone Programming

==>Click here for the SiteMap<==. Original contents with decent amount of source codes.

Sunday, April 16, 2006

How to use the new Camera API in Windows Mobile 5.0 SDK with only Embedded Visual C++ 4.0 (evc4)?

====>SiteMap of this Blog<===

How to use the new Camera API in Windows Mobile 5.0 SDK with only Embedded Visual C++ 4.0 (evc4)?

Almost all up-to-date phones, PDAs, or handheld gadgets have an embedded camera, allow users to snap pictures or capture videos. Microsoft releases new APIs in Windows Mobile 5.0 SDK to help developers controlling the camera.

Camera Capture API
Camera enabled devices are extremely popular. With these devices being so widely available, application developers now have the opportunity to substantially enhance the user experience by integrating the capture of both still and video images directly into their applications. To enable application developers to easily provide this functionality, Windows Mobile 5.0 provides the camera capture dialog. The unmanaged API is called SHCameraCapture.

The problem is that the only Visual Studio 2005 can work with Windows Mobile 5.0 SDK. What if you are still using the free Embedded Visual C++ 4 (EVC4), and you do not want to shed a cool $800 to get a copy of VS2005?

The solution is to use LoadLibrary to load aygshell.dll, get the entry point to SHCameraCapture, then call that function by jumping to the entry point. The API anticipates a structure as the parameter, so you need to instruct EVC4 compiler to generate the parameter correctly by defining it yourself. Luckily all the members in the structure are primitive types or character arrays, so there is really not much hassle.

Below is the source code that you can copy and paste into your EVC4 source code. It uses #ifdef _WIN32_WCE to make sure the code gets compiled for Pocket PC 2003 project or Smartphone 2003 project. The final executable can then be copied to a Pocket PC 5.0 device or Smartphone 5.0 device.

#include <aygshell.h>
#if _WIN32_WCE < 0x0500

// Flags for camera capture UI

typedef enum {

typedef enum {

typedef enum {

typedef struct tagSHCAMERACAPTURE
   DWORD   cbSize;
   HWND   hwndOwner;
   TCHAR   szFile[MAX_PATH];   
   LPCTSTR   pszInitialDir;
   LPCTSTR   pszDefaultFileName;
   LPCTSTR   pszTitle;
   DWORD   nResolutionWidth;
   DWORD   nResolutionHeight;
   DWORD   nVideoTimeLimit;


typedef HRESULT (*fnSHCameraCapture)(PSHCAMERACAPTURE pshcc);

   HRESULT hr = S_OK;
   HINSTANCE hAygShell = LoadLibrary(TEXT("aygshell.dll"));
   fnSHCameraCapture funcSHCameraCapture = NULL;

   if (!hAygShell) {
   hr = HRESULT_FROM_WIN32(GetLastError());
   goto FuncExit;
   funcSHCameraCapture = (fnSHCameraCapture)GetProcAddress(hAygShell, TEXT("SHCameraCapture"));
   if (!funcSHCameraCapture) {
   hr = HRESULT_FROM_WIN32(GetLastError());
   goto FuncExit;

   // call the API now
   hr = funcSHCameraCapture(pshcc);

   if (hAygShell) {
   return hr;

#endif   // faked one in 4.20/4.21 platform

Wrap Up

You may use similar approach to access other new 5.0 APIs from within EVC4. You need to find out which DLL exports the API, and more importantly, you need to let EVC4 compiler correctly generate parameters to feed into those APIs, so inevitably you have to copy some header definitions from Windows Mobile 5.0 SDKs.

====>SiteMap of this Blog<===

[ [permalink] ]


At May 10, 2006 3:30 PM, Anonymous Anonymous said...

Dear Lao K,

Thanks for your very interesting article. As I see in your web page, you have a lot of experience on mobile programming. I've tried successfully the SHCameraCapture function by calling this function either regular way and yours. But, I have a question, as I use the QTEK 9000 which has 2 cameras, the SHCameraCapture works only with the batery side camera, not the screen side one. I've searched but found nothing taking about this in the net. Do you have any idea?

Best regards,

At December 22, 2006 6:58 PM, Anonymous Anonymous said...

Dear Lao K, that was an interesting article. Not sure if there's similar workout using Java?

At March 02, 2008 1:41 PM, Anonymous Anonymous said...

Nice article. In a similar manner, I am attmepting to get low level access to the camera via directshow. Still using evc4, as the non camera portion of my app needs to run on lots of devices.
FindFirstDevice is the only strict API I seem to need, but I'm also using a bunch of code that requires the COM defines for direct show, like in this article

COM is supposed to let us acess these things, but I need the type libraries. WM5 downloads require VC 2005 to install. Any other options?

At November 04, 2009 4:14 PM, Blogger Adi said...

Find Internet Marketing resource hare Online Marketing Strategy | Internet Marketing Tools | Online Marketing Campaign | Online Marketing Business | Online Marketing System | Online Business | Online Home Business | Online Business Tips | Internet Marketing Online


Post a Comment

Links to this post:

Create a Link

<< Home