/*++
Copyright (c) Microsoft Corporation. All rights reserved.
--*/
#include "stdafx.h"
#include "resource.h"
#include "DataCallback.h"
#include "ProgressDlg.h"
#include "WiaWrap.h"
namespace WiaWrap
{
//////////////////////////////////////////////////////////////////////////
//
//
//
#ifndef MAX_GUID_STRING_LEN
#define MAX_GUID_STRING_LEN 39
#endif //MAX_GUID_STRING_LEN
//////////////////////////////////////////////////////////////////////////
//
// ReadPropertyLong
//
HRESULT
ReadPropertyLong(
IWiaPropertyStorage *pWiaPropertyStorage,
const PROPSPEC *pPropSpec,
LONG *plResult
)
{
PROPVARIANT PropVariant;
HRESULT hr = pWiaPropertyStorage->ReadMultiple(
1,
pPropSpec,
&PropVariant
);
// Generally, the return value should be checked against S_FALSE.
// If ReadMultiple returns S_FALSE, it means the property name or ID
// had valid syntax, but it didn't exist in this property set, so
// no properties were retrieved, and each PROPVARIANT structure is set
// to VT_EMPTY. But the following switch statement will handle this case
// and return E_FAIL. So the caller of ReadPropertyLong does not need
// to check for S_FALSE explicitly.
if (SUCCEEDED(hr))
{
switch (PropVariant.vt)
{
case VT_I1:
{
*plResult = (LONG) PropVariant.cVal;
hr = S_OK;
break;
}
case VT_UI1:
{
*plResult = (LONG) PropVariant.bVal;
hr = S_OK;
break;
}
case VT_I2:
{
*plResult = (LONG) PropVariant.iVal;
hr = S_OK;
break;
}
case VT_UI2:
{
*plResult = (LONG) PropVariant.uiVal;
hr = S_OK;
break;
}
case VT_I4:
{
*plResult = (LONG) PropVariant.lVal;
hr = S_OK;
break;
}
case VT_UI4:
{
*plResult = (LONG) PropVariant.ulVal;
hr = S_OK;
break;
}
case VT_INT:
{
*plResult = (LONG) PropVariant.intVal;
hr = S_OK;
break;
}
case VT_UINT:
{
*plResult = (LONG) PropVariant.uintVal;
hr = S_OK;
break;
}
case VT_R4:
{
*plResult = (LONG) (PropVariant.fltVal + 0.5);
hr = S_OK;
break;
}
case VT_R8:
{
*plResult = (LONG) (PropVariant.dblVal + 0.5);
hr = S_OK;
break;
}
default:
{
hr = E_FAIL;
break;
}
}
}
PropVariantClear(&PropVariant);
return hr;
}
//////////////////////////////////////////////////////////////////////////
//
// ReadPropertyGuid
//
HRESULT
ReadPropertyGuid(
IWiaPropertyStorage *pWiaPropertyStorage,
const PROPSPEC *pPropSpec,
GUID *pguidResult
)
{
PROPVARIANT PropVariant;
HRESULT hr = pWiaPropertyStorage->ReadMultiple(
1,
pPropSpec,
&PropVariant
);
// Generally, the return value should be checked against S_FALSE.
// If ReadMultiple returns S_FALSE, it means the property name or ID
// had valid syntax, but it didn't exist in this property set, so
// no properties were retrieved, and each PROPVARIANT structure is set
// to VT_EMPTY. But the following switch statement will handle this case
// and return E_FAIL. So the caller of ReadPropertyGuid does not need
// to check for S_FALSE explicitly.
if (SUCCEEDED(hr))
{
switch (PropVariant.vt)
{
case VT_CLSID:
{
*pguidResult = *PropVariant.puuid;
hr = S_OK;
break;
}
case VT_BSTR:
{
hr = CLSIDFromString(PropVariant.bstrVal, pguidResult);
break;
}
case VT_LPWSTR:
{
hr = CLSIDFromString(PropVariant.pwszVal, pguidResult);
break;
}
case VT_LPSTR:
{
WCHAR wszGuid[MAX_GUID_STRING_LEN];
mbstowcs_s(NULL, wszGuid, MAX_GUID_STRING_LEN, PropVariant.pszVal, MAX_GUID_STRING_LEN);
wszGuid[MAX_GUID_STRING_LEN - 1] = L'\0';
hr = CLSIDFromString(wszGuid, pguidResult);
break;
}
default:
{
hr = E_FAIL;
break;
}
}
}
PropVariantClear(&PropVariant);
return hr;
}
//////////////////////////////////////////////////////////////////////////
//
// WiaGetNumDevices
//
HRESULT
WiaGetNumDevices(
IWiaDevMgr *pSuppliedWiaDevMgr,
ULONG *pulNumDevices
)
{
HRESULT hr;
// Validate and initialize output parameters
if (pulNumDevices == NULL)
{
return E_POINTER;
}
*pulNumDevices = 0;
// Create a connection to the local WIA device manager
CComPtr<IWiaDevMgr> pWiaDevMgr = pSuppliedWiaDevMgr;
if (pWiaDevMgr == NULL)
{
hr = pWiaDevMgr.CoCreateInstance(CLSID_WiaDevMgr);
if (FAILED(hr))
{
return hr;
}
}
// Get a list of all the WIA devices on the system
CComPtr<IEnumWIA_DEV_INFO> pIEnumWIA_DEV_INFO;
hr = pWiaDevMgr->EnumDeviceInfo(
0,
&pIEnumWIA_DEV_INFO
);
if (FAILED(hr))
{
return hr;
}
// Get the number of WIA devices
ULONG celt;
hr = pIEnumWIA_DEV_INFO->GetCount(&celt);
if (FAILED(hr))
{
return hr;
}
*pulNumDevices = celt;
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
//
// DefaultProgressCallback
//
HRESULT
CALLBACK
DefaultProgressCallback(
LONG lStatus,
LONG lPercentComplete,
PVOID pParam
)
{
CProgressDlg *pProgressDlg = (CProgressDlg *) pParam;
if (pProgressDlg == NULL)
{
return E_POINTER;
}
// If the user has pressed the cancel button, abort transfer
if (pProgressDlg->Cancelled())
{
return S_FALSE;
}
// Form the message text
UINT uID;
switch (lStatus)
{
case IT_STATUS_TRANSFER_FROM_DEVICE:
{
uID = IDS_STATUS_TRANSFER_FROM_DEVICE;
break;
}
case IT_STATUS_PROCESSING_DATA:
{
uID = IDS_STATUS_PROCESSING_DATA;
break;
}
case IT_STATUS_TRANSFER_TO_CLIENT:
{
uID = IDS_STATUS_TRANSFER_TO_CLIENT;
break;
}
default:
{
return E_INVALIDARG;
}
}
TCHAR szFormat[DEFAULT_STRING_SIZE] = _T("%d");
LoadString(g_hInstance, uID, szFormat, COUNTOF(szFormat));
TCHAR szStatusText[DEFAULT_STRING_SIZE];
_sntprintf_s(szStatusText, COUNTOF(szStatusText), COUNTOF(szStatusText) - 1, szFormat, lPercentComplete);
szStatusText[COUNTOF(szStatusText) - 1] = _T('\0');
// Update the progress bar values
pProgressDlg->SetMessage(szStatusText);
pProgressDlg->SetPercent(lPercentComplete);
return S_OK;
}
///////////////////////////////
没有合适的资源?快使用搜索试试~ 我知道了~
Windows 图像获取 API 使用方法
共22个文件
cpp:9个
h:9个
sln:1个
需积分: 14 20 下载量 164 浏览量
2009-01-13
15:37:06
上传
评论 1
收藏 33KB ZIP 举报
温馨提示
WIA API 集包含用于文件传输的简单 API,但不包含用于内存中传输的简单 API 调用。GetImage 实现名为 WiaGetImage 的包装函数,它将 SelectDeviceDlg、DeviceDlg 和 idtGetBandedData API 的功能组合起来以完全将图像获取封装在单个函数调用内。
资源推荐
资源详情
资源评论
收起资源包目录
GetImage.zip (22个子文件)
GetImage
GetImage.sln 2KB
WiaWrap.cpp 16KB
DataCallback.h 3KB
StdAfx.cpp 102B
resource.h 1KB
EventCallback.cpp 3KB
BitmapUtil.cpp 11KB
GetImage.rc 4KB
EventCallback.h 2KB
BitmapUtil.h 6KB
MainWnd.cpp 8KB
GetImage.vcproj 15KB
DataCallback.cpp 9KB
GetImage.cpp 2KB
BitmapWnd.cpp 5KB
StdAfx.h 656B
WiaWrap.h 15KB
ProgressDlg.h 2KB
ReadMe.htm 9KB
MainWnd.h 2KB
BitmapWnd.h 2KB
ProgressDlg.cpp 6KB
共 22 条
- 1
资源评论
xklzq
- 粉丝: 7
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功