📄 wiahelpers.cpp
字号:
/**************************************************************************
*
* Copyright (c) 2003 Microsoft Corporation
*
* Title: wiahelpers.cpp
*
* Description: This file contains a number of helper functions
* for child item creation etc.
*
***************************************************************************/
#include "stdafx.h"
#include <strsafe.h>
static FILM_FRAME g_FilmFrames[] = { { 36, 27, 222, 167 },
{ 36, 221, 222, 167 },
{ 37, 418, 222, 167 },
{ 37, 614, 221, 172 } };
/**
* This function creates a full WIA item name
* from a given WIA item name.
*
* The new full item name is created by concatinating
* the WIA item name with the parent's full item name.
*
* (e.g. 0000\Root + MyItem = 0000\Root\MyItem)
*
* @param pParent IWiaDrvItem interface of the parent WIA driver item
* @param bstrItemName
* Name of the WIA item
* @param pbstrFullItemName
* Returned full item name. This parameter
* cannot be NULL.
* @return S_OK - if successful
* E_XXXXXXXX - failure result
*/
HRESULT MakeFullItemName(
__in IWiaDrvItem *pParent,
__in BSTR bstrItemName,
__out BSTR *pbstrFullItemName)
{
HRESULT hr = S_OK;
if((pParent)&&(bstrItemName)&&(pbstrFullItemName))
{
BSTR bstrParentFullItemName = NULL;
hr = pParent->GetFullItemName(&bstrParentFullItemName);
if(SUCCEEDED(hr))
{
CBasicStringWide cswFullItemName;
cswFullItemName.Format(TEXT("%ws\\%ws"),bstrParentFullItemName,bstrItemName);
*pbstrFullItemName = SysAllocString(cswFullItemName.String());
if(*pbstrFullItemName)
{
hr = S_OK;
}
else
{
hr = E_OUTOFMEMORY;
WIAS_ERROR((g_hInst, "Failed to allocate memory for BSTR full item name, hr = 0x%lx",hr));
}
SysFreeString(bstrParentFullItemName);
bstrParentFullItemName = NULL;
}
else
{
WIAS_ERROR((g_hInst, "Failed to get full item name from parent IWiaDrvItem, hr = 0x%lx",hr));
}
}
else
{
hr = E_INVALIDARG;
WIAS_ERROR((g_hInst, "Invalid parameters were passed, hr = 0x%lx",hr));
}
return hr;
}
/**
* This function creates a WIA child item
*
* @param wszItemName
* Item name
* @param pIWiaMiniDrv
* WIA minidriver interface
* @param pParent Parent's WIA driver item interface
* @param lItemFlags Item flags
* @param guidItemCategory
* Item category
* @param ppChild Pointer to the newly created child item
* @param wszStoragePath
* Storage data path
* @return
*/
HRESULT CreateWIAChildItem(
__in LPOLESTR wszItemName,
__in IWiaMiniDrv *pIWiaMiniDrv,
__in IWiaDrvItem *pParent,
LONG lItemFlags,
GUID guidItemCategory,
__out_opt IWiaDrvItem **ppChild,
__in const WCHAR *wszStoragePath)
{
HRESULT hr = E_INVALIDARG;
if((wszItemName)&&(pIWiaMiniDrv)&&(pParent))
{
BSTR bstrItemName = SysAllocString(wszItemName);
BSTR bstrFullItemName = NULL;
IWiaDrvItem *pIWiaDrvItem = NULL;
if (bstrItemName)
{
hr = MakeFullItemName(pParent,bstrItemName,&bstrFullItemName);
if(SUCCEEDED(hr))
{
WIA_DRIVER_ITEM_CONTEXT *pWiaDriverItemContext = NULL;
hr = wiasCreateDrvItem(lItemFlags,
bstrItemName,
bstrFullItemName,
pIWiaMiniDrv,
sizeof(WIA_DRIVER_ITEM_CONTEXT),
(BYTE **)&pWiaDriverItemContext,
&pIWiaDrvItem);
if(SUCCEEDED(hr))
{
pWiaDriverItemContext->ulFeederTransferCount = 0;
pWiaDriverItemContext->guidItemCategory = guidItemCategory;
if(wszStoragePath)
{
pWiaDriverItemContext->bstrStorageDataPath = SysAllocString(wszStoragePath);
if(!pWiaDriverItemContext->bstrStorageDataPath)
{
hr = E_OUTOFMEMORY;
WIAS_ERROR((g_hInst, "Failed to allocate memory for BSTR storage item path, hr = 0x%lx",hr));
}
}
if(SUCCEEDED(hr))
{
hr = pIWiaDrvItem->AddItemToFolder(pParent);
if(FAILED(hr))
{
WIAS_ERROR((g_hInst, "Failed to add the new WIA item (%ws) to the specified parent item, hr = 0x%lx",bstrFullItemName,hr));
pIWiaDrvItem->Release();
pIWiaDrvItem = NULL;
}
//
// If a child iterface pointer parameter was specified, then the caller
// expects to have the newly created child interface pointer returned to
// them. (do not release the newly created item, in this case)
//
if(ppChild)
{
*ppChild = pIWiaDrvItem;
pIWiaDrvItem = NULL;
}
else if (pIWiaDrvItem)
{
//
// The newly created child has been added to the tree, and is no longer
// needed. Release it.
//
pIWiaDrvItem->Release();
pIWiaDrvItem = NULL;
}
}
}
else
{
WIAS_ERROR((g_hInst, "Failed to create the new WIA driver item, hr = 0x%lx",hr));
}
SysFreeString(bstrItemName);
bstrItemName = NULL;
SysFreeString(bstrFullItemName);
bstrFullItemName = NULL;
}
else
{
WIAS_ERROR((g_hInst, "Failed to create the new WIA item's full item name, hr = 0x%lx",hr));
}
}
else
{
//
// Failed to allocate memory for bstrItemName.
//
hr = E_OUTOFMEMORY;
WIAS_ERROR((g_hInst, "Failed to allocate memory for BSTR storage item name"));
}
}
else
{
WIAS_ERROR((g_hInst, "Invalid parameters were passed"));
}
return hr;
}
/**
* This function creates a WIA flatbed item. WIA
* flatbed items will automatically have the
* WIA category setting of WIA_CATEGORY_FLATBED.
*
* @param wszItemName
* Item name
* @param pIWiaMiniDrv
* WIA minidriver interface
* @param pParent Parent's WIA driver item interface
* @return
*/
HRESULT CreateWIAFlatbedItem(
__in LPOLESTR wszItemName,
__in IWiaMiniDrv *pIWiaMiniDrv,
__in IWiaDrvItem *pParent)
{
LONG lItemFlags = WiaItemTypeImage | WiaItemTypeTransfer | WiaItemTypeFile | WiaItemTypeProgrammableDataSource | WiaItemTypeFolder;
return CreateWIAChildItem(wszItemName,pIWiaMiniDrv,pParent,lItemFlags, WIA_CATEGORY_FLATBED,NULL);
}
/**
* This function creates a WIA feeder item. WIA
* feeder items will automatically have the
* WIA category setting of WIA_CATEGORY_FEEDER.
*
* @param wszItemName
* Item name
* @param pIWiaMiniDrv
* WIA minidriver interface
* @param pParent Parent's WIA driver item interface
* @return
*/
HRESULT CreateWIAFeederItem(
__in LPOLESTR wszItemName,
__in IWiaMiniDrv *pIWiaMiniDrv,
__in IWiaDrvItem *pParent)
{
LONG lItemFlags = WiaItemTypeImage | WiaItemTypeTransfer | WiaItemTypeFile | WiaItemTypeProgrammableDataSource;
return CreateWIAChildItem(wszItemName,pIWiaMiniDrv,pParent,lItemFlags, WIA_CATEGORY_FEEDER,NULL);
}
/**
* This function creates a WIA film item. WIA
* film items will automatically have the
* WIA category setting of WIA_CATEGORY_FILM.
*
* @param wszItemName
* Item name
* @param pIWiaMiniDrv
* WIA minidriver interface
* @param pParent Parent's WIA driver item interface
* @return
*/
HRESULT CreateWIAFilmItem(
__in LPOLESTR wszItemName,
__in IWiaMiniDrv *pIWiaMiniDrv,
__in IWiaDrvItem *pParent)
{
LONG lItemFlags = WiaItemTypeImage | WiaItemTypeTransfer | WiaItemTypeFolder | WiaItemTypeProgrammableDataSource;
IWiaDrvItem *pChild = NULL;
HRESULT hr = S_OK;
hr = CreateWIAChildItem(wszItemName,pIWiaMiniDrv,pParent,lItemFlags, WIA_CATEGORY_FILM,&pChild);
if(SUCCEEDED(hr))
{
if(pChild)
{
lItemFlags = WiaItemTypeImage | WiaItemTypeTransfer | WiaItemTypeFile | WiaItemTypeProgrammableDataSource;
hr = CreateWIAChildItem(L"Frame1",pIWiaMiniDrv,pChild,lItemFlags, WIA_CATEGORY_FILM,NULL);
if(SUCCEEDED(hr))
{
hr = CreateWIAChildItem(L"Frame2",pIWiaMiniDrv,pChild,lItemFlags, WIA_CATEGORY_FILM,NULL);
}
if(SUCCEEDED(hr))
{
hr = CreateWIAChildItem(L"Frame3",pIWiaMiniDrv,pChild,lItemFlags, WIA_CATEGORY_FILM,NULL);
}
if(SUCCEEDED(hr))
{
hr = CreateWIAChildItem(L"Frame4",pIWiaMiniDrv,pChild,lItemFlags, WIA_CATEGORY_FILM,NULL);
}
pChild->Release();
pChild = NULL;
}
}
return hr;
}
/**
* This function creates the main sample WIA storage item.
* WIA storage items should have either the WIA category
* of WIA_CATEGORY_FINISHED_FILE (for stored image files)
* or WIA_CATEGORY_FOLDER (for storage folder items).
*
* @param wszItemName
* Item name
* @param pIWiaMiniDrv
* WIA minidriver interface
* @param pParent
* Parent's WIA driver item interface
* @return
*/
HRESULT CreateWIAStorageItem(
__in LPOLESTR wszItemName,
__in IWiaMiniDrv *pIWiaMiniDrv,
__in IWiaDrvItem *pParent,
__in const WCHAR * wszStoragePath)
{
LONG lItemFlags = WiaItemTypeFolder | WiaItemTypeStorage;
IWiaDrvItem *pChild = NULL;
HRESULT hr = S_OK;
hr = CreateWIAChildItem(wszItemName, pIWiaMiniDrv, pParent, lItemFlags, WIA_CATEGORY_FOLDER, &pChild);
if (SUCCEEDED(hr))
{
if (pChild)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -