📄 driver.cpp
字号:
COMMAND_BYTE_COUNT+cbBytes,
NULL);
}
}
g_pStiDevice->UnLockDevice();
if (!SUCCEEDED(hres)) Reset();
return SUCCEEDED(hres);
}
BOOL CDriver::Reset()
{
if (!g_pStiDevice)
return FALSE;
HRESULT hres = STI_OK;
hres = g_pStiDevice->LockDevice(LOCK_TIMEOUT);
if (SUCCEEDED(hres))
{
hres = g_pStiDevice->DeviceReset();
g_pStiDevice->UnLockDevice();
}
return SUCCEEDED(hres);
}
BOOL CDriver::EnableNotifications()
{
if (!g_pStiDevice)
return FALSE;
// IF we are already subscribed then we are set to go
if (g_hEvent != INVALID_HANDLE_VALUE)
return TRUE;
HRESULT hres = STI_OK;
g_hEvent = ::CreateEvent( NULL, TRUE, FALSE, NULL );
if (g_hEvent != INVALID_HANDLE_VALUE)
{
STISUBSCRIBE stiSubscribe;
stiSubscribe.dwSize = sizeof( STISUBSCRIBE );
stiSubscribe.dwFlags = STI_SUBSCRIBE_FLAG_EVENT;
stiSubscribe.dwFilter = 0;
stiSubscribe.hWndNotify = 0;
stiSubscribe.hEvent = g_hEvent;
stiSubscribe.uiNotificationMessage = 0;
hres = g_pStiDevice->Subscribe(&stiSubscribe);
}
if FAILED(hres)
{
::CloseHandle(g_hEvent);
g_hEvent = INVALID_HANDLE_VALUE;
}
return SUCCEEDED(hres);
}
BOOL CDriver::DisableNotifications()
{
// We should be connected to the device object and
// have subscribed to device events
if (!g_pStiDevice || (g_hEvent == INVALID_HANDLE_VALUE))
return FALSE;
HRESULT hres = STI_OK;
hres = g_pStiDevice->UnSubscribe();
::CloseHandle(g_hEvent);
g_hEvent = INVALID_HANDLE_VALUE;
return SUCCEEDED(hres);
}
BOOL CDriver::CheckForEvents(bool& bEventOccured, GUID& guidEventCode)
{
// See if we are subscribed
if (g_hEvent != INVALID_HANDLE_VALUE)
{
// Test the event object to see if it has been set.
bEventOccured =
(::WaitForSingleObject(g_hEvent, 0) != WAIT_TIMEOUT);
// if it has then we have an event in which case we will
// need to reset the event handle
if (bEventOccured)
{
::ResetEvent(g_hEvent);
// Get the event guid
STINOTIFY stEventData;
stEventData.dwSize = sizeof(stEventData);
HRESULT hres = g_pStiDevice->GetLastNotificationData(&stEventData);
guidEventCode = stEventData.guidNotificationCode;
}
return TRUE;
}
return FALSE;
}
BOOL CDriver::QueryStatus(LPDWORD dwOnlineState, LPDWORD dwEventState)
{
if (!g_pStiDevice)
return FALSE;
HRESULT hres = STI_OK;
hres = g_pStiDevice->LockDevice(LOCK_TIMEOUT);
if (SUCCEEDED(hres))
{
STI_DEVICE_STATUS stStatus;
stStatus.StatusMask = STI_DEVSTATUS_ONLINE_STATE |
STI_DEVSTATUS_EVENTS_STATE;
stStatus.dwSize = sizeof(stStatus);
hres = g_pStiDevice->GetStatus(&stStatus);
if (SUCCEEDED(hres))
{
*dwOnlineState = stStatus.dwOnlineState;
*dwEventState = stStatus.dwEventHandlingState;
}
g_pStiDevice->UnLockDevice();
}
return SUCCEEDED(hres);
}
/*****************************************************************************
HRESULT StiDeviceRelease( )
Close the Sti subsystem
Parameters:
none
Return:
HRESULT of last Sti call
*****************************************************************************/
HRESULT StiDeviceRelease( )
{
HRESULT hres = STI_OK;
//
// The STI_DEVICE_INFORMATION array returned by GetDeviceList needs to
// be freed with LocalFree(). Also, resetting internal Sti device counter.
//
if (g_pStiInfo)
LocalFree(g_pStiInfo);
g_pStiInfo = g_pStiInfoPtr = NULL;
g_dwStiTotal = 0;
//
// close device if any are open
//
if (g_pStiDevice) {
// If we are subscribed to the device's events
// time to unsubscribe now
if (g_hEvent != INVALID_HANDLE_VALUE)
{
g_pStiDevice->UnSubscribe();
::CloseHandle(g_hEvent);
}
//
// Close an open device.
//
hres = g_pStiDevice->Release();
//
// clear the Sti device pointer
//
g_pStiDevice = NULL;
}
return (hres);
}
/*****************************************************************************
HRESULT StiImageRelease( )
Close the Sti subsystem
Parameters:
none
Return:
HRESULT of last Sti call
*****************************************************************************/
HRESULT StiImageRelease( )
{
HRESULT hres = STI_OK;
//
// if Sti subsystem is open, close it
//
if (g_pSti) {
//
// Close the Still Imaging subsystem.
//
hres = g_pSti->Release();
//
// clear the Sti subsystem pointer
//
g_pSti = NULL;
}
return (hres);
}
/*****************************************************************************
HRESULT StiWriteErrLog(DWORD dwSeverity,LPCWSTR pszMessage)
Write a string to the error log
Parameters:
DWORD severity, which can be
STI_TRACE_INFORMATION
STI_TRACE_WARNING
STI_TRACE_ERROR
Wide character message to write to log.
Return:
HRESULT of last Sti call
*****************************************************************************/
HRESULT StiWriteErrLog(DWORD dwSeverity,LPCWSTR pszMessage)
{
HRESULT hres = STI_OK;
//
// check that STI subsystem is loaded
//
if (! g_pSti)
return (-1);
//
// WriteToErrorLog can be used to write debugging and diagnostic
// information into the STI log file, located in the Windows directory
// STI_TRACE.LOG. The user can control whether informational, warning or
// error messages, or any combination of these three are put in the log
// file through the Scanners & Cameras control panel.
//
hres = g_pSti->WriteToErrorLog(
dwSeverity, // severity of error
pszMessage // string to write to log
);
return (hres);
}
BOOL CDriver::EnableRemoteWakeup()
{
if (!g_pStiDevice)
return FALSE;
HRESULT hres = STI_OK;
hres = g_pStiDevice->LockDevice(LOCK_TIMEOUT);
if (SUCCEEDED(hres))
{
DWORD cbCount;
hres = g_pStiDevice->Escape(IOCTL_ENABLE_REMOTEWAKEUP,
NULL,
0,
NULL,
0,
&cbCount);
}
g_pStiDevice->UnLockDevice();
return SUCCEEDED(hres);
}
BOOL CDriver::DisableRemoteWakeup()
{
if (!g_pStiDevice)
return FALSE;
HRESULT hres = STI_OK;
hres = g_pStiDevice->LockDevice(LOCK_TIMEOUT);
if (SUCCEEDED(hres))
{
DWORD cbCount;
hres = g_pStiDevice->Escape(IOCTL_DISABLE_REMOTEWAKEUP,
NULL,
0,
NULL,
0,
&cbCount);
}
g_pStiDevice->UnLockDevice();
return SUCCEEDED(hres);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -