使用 Pocket PC 2003 应用程序中的 SHCameraCapture
这个迷你系列包含两篇文章,介绍了使用 SHCameraCapture 的两种场景。
引言
这个迷你系列包含两篇文章,介绍了使用 SHCameraCapture
的两种场景。
背景
第一篇名为 在 Pocket PC 2003 应用程序中使用 SHCameraCapture。本文描述了从为 Pocket PC 2003 设备构建的 C++ 项目访问 SHCameraCapture API 所需的步骤。
第二篇名为 如果 SHCameraCapture 返回 E_FAIL,该怎么办?。 在这篇文章中,我描述了我使用该 API 的经验,以及我最终解决问题的方法。
为什么从 Pocket PC 2003 项目中使用 SHCameraCapture 会有问题? 好吧,你不应该一开始就这么做:SHCameraCapture
仅适用于 Windows Mobile 5 及更高版本。 然而,在我的例子中,应用程序必须在 Pocket PC 2003 和更新的设备上运行,并且如果设备不是最新的平台,则应该优雅地降级。 图像捕获就是这样一个功能:如果设备具有摄像头,并且其操作系统是 WM5 或更高版本,则应该支持图像捕获。 如果它较旧,则应该仍然可以工作,而无需此功能。
因此,我们为 ARM 架构构建了应用程序,并使用了 Pocket PC 2003 SDK(真的相当麻烦)。 这意味着编译器不知道这个 API,尽管该功能存在于我们的大多数设备上。
以下是如何操作。
要通过 COM 访问 API,请使用以下代码
#include "aygshell.h"
#if _WIN32_WCE < 0x0500
// We are compiling for a pre-WindowsMobile5 platform.
//////////////////////////////////////////////////////////////////////////////
//
// Interface for camera capture UI
//
// aygshell.dll is loaded dynamically to make compiling for PocketPC2003 possible.
// When executed on Windows Mobile 5 or later, tha camera is supported (by
// loading the aygshell.dll).
typedef enum {
CAMERACAPTURE_MODE_STILL = 0,
CAMERACAPTURE_MODE_VIDEOONLY,
CAMERACAPTURE_MODE_VIDEOWITHAUDIO,
} CAMERACAPTURE_MODE;
typedef enum {
CAMERACAPTURE_STILLQUALITY_DEFAULT = 0,
CAMERACAPTURE_STILLQUALITY_LOW,
CAMERACAPTURE_STILLQUALITY_NORMAL,
CAMERACAPTURE_STILLQUALITY_HIGH,
} CAMERACAPTURE_STILLQUALITY;
typedef enum {
CAMERACAPTURE_VIDEOTYPE_ALL = 0xFFFF,
CAMERACAPTURE_VIDEOTYPE_STANDARD = 1,
CAMERACAPTURE_VIDEOTYPE_MESSAGING = 2,
} CAMERACAPTURE_VIDEOTYPES;
typedef struct tagSHCAMERACAPTURE
{
DWORD cbSize;
HWND hwndOwner;
TCHAR szFile[MAX_PATH];
LPCTSTR pszInitialDir;
LPCTSTR pszDefaultFileName;
LPCTSTR pszTitle;
CAMERACAPTURE_STILLQUALITY StillQuality;
CAMERACAPTURE_VIDEOTYPES VideoTypes;
DWORD nResolutionWidth;
DWORD nResolutionHeight;
DWORD nVideoTimeLimit;
CAMERACAPTURE_MODE Mode;
} SHCAMERACAPTURE, *PSHCAMERACAPTURE;
HRESULT SHCameraCapture(PSHCAMERACAPTURE pshcc);
typedef HRESULT (*fnSHCameraCapture)(PSHCAMERACAPTURE pshcc);
// Wrapper for the SHCameraCapture method in aygshell.dll.
// It loads the dll, invokes SHCameraCapture(), and unloads the dll.
HRESULT SHCameraCapture(PSHCAMERACAPTURE pshcc);
#endif // _WIN32_WCE < 0x0500
#if _WIN32_WCE < 0x0500
// We are compiling for a pre-WindowsMobile5 platform.
//------------------------------------------------------------------
// Wrapper method for pre-Windows Mobile 5 platforms.
// The SHCameraCapture call exists on WM5, but not on previous WINCE OSs.
// This wrapper makes it available if the client supports it, even if we compile
// for Pocket PC 2003 clients.
//
// Parameters:
// pshcc - (Pointer to a ) PSHCAMERACAPTURE structure.
// See the documentation of SHCameraCapture for details.
//
// Return value:
// HRESULT - See the documentation of SHCameraCapture for details.
//
//------------------------------------------------------------------
HRESULT SHCameraCapture(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, _T("SHCameraCapture"));
if (!funcSHCameraCapture) {
hr = HRESULT_FROM_WIN32(GetLastError());
goto FuncExit;
}
// call the API now
hr = funcSHCameraCapture(pshcc);
// Possible errors returned:
// E_INVALIDARG (0x80070057L)
// E_OUTOFMEMORY
FuncExit:
if (hAygShell) {
FreeLibrary(hAygShell);
}
return hr;
}
#endif // _WIN32_WCE < 0x0500
评论:对于上述解决方案,我使用了来自网络上的某人的代码,但我无法再找到它以添加引用。 如果您发现上述方法与您的代码相似,请留下评论,我将添加引用。
代码的第一部分来自 Microsoft 头文件。