📄 testmcro.cpp
字号:
VOID CheckButtonStatus(PVAL pValue)
{
//
// Button Polling is done here...
//
//
// Check your device for button presses
//
LONG lButtonValue = 0;
GetButtonPress(&lButtonValue);
switch (lButtonValue) {
case 1:
pValue->pGuid = (GUID*) &guidScanButton;
Trace(TEXT("Scan Button Pressed!"));
break;
default:
pValue->pGuid = (GUID*) &GUID_NULL;
break;
}
}
/**************************************************************************\
* GetInterruptEvent (helper)
*
* Called by the MicroDriver to handle USB interrupt events.
*
* Arguments:
*
* pValue - VAL structure used for settings
*
*
* Return Value:
*
* Status
*
* History:
*
* 1/20/2000 Original Version
*
\**************************************************************************/
HRESULT GetInterruptEvent(PVAL pValue)
{
//
// Below is a simple example of how DeviceIOControl() can be used to
// determine interrupts with a USB device.
//
// The test device does not support events,
// So this should not be called.
//
BYTE InterruptData;
DWORD dwIndex;
DWORD dwError;
OVERLAPPED Overlapped;
ZeroMemory( &Overlapped, sizeof( Overlapped ));
Overlapped.hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
HANDLE hEventArray[2] = {pValue->handle, Overlapped.hEvent};
BOOL fLooping = TRUE;
BOOL bRet = TRUE;
//
// use the Handle created in CMD_INITIALIZE.
//
HANDLE InterruptHandle = pValue->pScanInfo->DeviceIOHandles[1];
while (fLooping) {
//
// Set the wait event, for the interrupt
//
bRet = DeviceIoControl( InterruptHandle,
IOCTL_WAIT_ON_DEVICE_EVENT,
NULL,
0,
&InterruptData,
sizeof(InterruptData),
&dwError,
&Overlapped );
if ( bRet || ( !bRet && ( ::GetLastError() == ERROR_IO_PENDING ))) {
//
// Wait for the event to happen
//
dwIndex = WaitForMultipleObjects( 2,
hEventArray,
FALSE,
INFINITE );
//
// Trap the result of the event
//
switch ( dwIndex ) {
case WAIT_OBJECT_0+1:
DWORD dwBytesRet;
bRet = GetOverlappedResult( InterruptHandle, &Overlapped, &dwBytesRet, FALSE );
if ( dwBytesRet ) {
//
// assign the corresponding button GUID to the *pValue->pGuid
// member., and Set the event.
//
// Change detected - signal
if (*pValue->pHandle != INVALID_HANDLE_VALUE) {
switch ( InterruptData ) {
case 1:
*pValue->pGuid = guidScanButton;
Trace(TEXT("Scan Button Pressed!"));
break;
default:
*pValue->pGuid = GUID_NULL;
break;
}
Trace(TEXT("Setting This Event by Handle %d"),*pValue->pHandle);
//
// signal the event, after a button GUID was assigned.
//
SetEvent(*pValue->pHandle);
}
break;
}
//
// reset the overlapped event
//
ResetEvent( Overlapped.hEvent );
break;
case WAIT_OBJECT_0:
// Fall through
default:
fLooping = FALSE;
}
}
else {
dwError = ::GetLastError();
break;
}
}
return S_OK;
}
/**************************************************************************\
* GetButtonPress (helper)
*
* Called by the MicroDriver to set the actual button value pressed
*
* Arguments:
*
* pButtonValue - actual button pressed
*
*
* Return Value:
*
* Status
*
* History:
*
* 1/20/2000 Original Version
*
\**************************************************************************/
VOID GetButtonPress(LONG *pButtonValue)
{
//
// This where you can set your button value
//
pButtonValue = 0;
}
/**************************************************************************\
* GetButtonCount (helper)
*
* Called by the MicroDriver to get the number of buttons a device supports
*
* Arguments:
*
* none
*
* Return Value:
*
* LONG - number of supported buttons
*
* History:
*
* 1/20/2000 Original Version
*
\**************************************************************************/
LONG GetButtonCount()
{
LONG ButtonCount = 0;
//
// Since the test device does not have a button,
// set this value to 0. For a real device with a button,
// set (LONG ButtonCount = 1;)
//
//
// determine the button count of your device
//
return ButtonCount;
}
/**************************************************************************\
* GetOLDSTRResourceString (helper)
*
* Called by the MicroDriver to Load a resource string in OLESTR format
*
* Arguments:
*
* lResourceID - String resource ID
* ppsz - Pointer to a OLESTR to be filled with the loaded string
* value
* bLocal - Possible, other source for loading a resource string.
*
*
* Return Value:
*
* Status
*
* History:
*
* 1/20/2000 Original Version
*
\**************************************************************************/
HRESULT GetOLESTRResourceString(LONG lResourceID,__deref_out LPOLESTR *ppsz,BOOL bLocal)
{
HRESULT hr = S_OK;
TCHAR szStringValue[255];
if(bLocal) {
//
// We are looking for a resource in our own private resource file
//
INT NumTCHARs = LoadString(g_hInst, lResourceID, szStringValue, sizeof(szStringValue)/sizeof(TCHAR));
DWORD dwError = GetLastError();
if (NumTCHARs <= 0)
{
#ifdef UNICODE
Trace(TEXT("NumTCHARs = %d dwError = %d Resource ID = %d (UNICODE)szString = %ws"),
NumTCHARs,
dwError,
lResourceID,
szStringValue);
#else
Trace(TEXT("NumTCHARs = %d dwError = %d Resource ID = %d (ANSI)szString = %s"),
NumTCHARs,
dwError,
lResourceID,
szStringValue);
#endif
return E_FAIL;
}
//
// NOTE: caller must free this allocated BSTR
//
#ifdef UNICODE
*ppsz = NULL;
*ppsz = (LPOLESTR)CoTaskMemAlloc(sizeof(szStringValue));
if(*ppsz != NULL)
{
//
// The call to LoadString previously guarantees that szStringValue is null terminated (maybe truncated)
// so a buffer of 'sizeof(szStringValue)/sizeof(TCHAR)' should suffice
//
hr = StringCchCopy(*ppsz, sizeof(szStringValue)/sizeof(TCHAR), szStringValue);
}
else
{
hr = E_OUTOFMEMORY;
}
#else
WCHAR wszStringValue[255];
ZeroMemory(wszStringValue,sizeof(wszStringValue));
//
// convert szStringValue from char* to unsigned short* (ANSI only)
//
MultiByteToWideChar(CP_ACP,
MB_PRECOMPOSED,
szStringValue,
lstrlenA(szStringValue)+1,
wszStringValue,
(sizeof(wszStringValue)/sizeof(WCHAR)));
*ppsz = NULL;
*ppsz = (LPOLESTR)CoTaskMemAlloc(sizeof(wszStringValue));
if(*ppsz != NULL)
{
//
// The call to LoadString & MultiByteToWideChar previously guarantees that wszStringValue is null terminated
// (maybe truncated) so a buffer of 'sizeof(wszStringValue)/sizeof(WCHAR)' should suffice
//
hr = StringCchCopyW(*ppsz,sizeof(wszStringValue)/sizeof(WCHAR),wszStringValue);
}
else
{
hr = E_OUTOFMEMORY;
}
#endif
}
else
{
//
// looking another place for resources??
//
hr = E_NOTIMPL;
}
return hr;
}
/**************************************************************************\
* Trace
*
* Called by the MicroDriver to output strings to a debugger
*
* Arguments:
*
* format - formatted string to output
*
*
* Return Value:
*
* VOID
*
* History:
*
* 1/20/2000 Original Version
*
\**************************************************************************/
VOID Trace(LPCTSTR format,...)
{
#ifdef DEBUG
TCHAR Buffer[1024];
va_list arglist;
va_start(arglist, format);
//
// StringCchVPrintf API guarantees the buffer to be null terminated (though it maybe truncated)
//
StringCchVPrintf(Buffer, sizeof(Buffer)/sizeof(TCHAR), format, arglist);
va_end(arglist);
OutputDebugString(Buffer);
OutputDebugString(TEXT("\n"));
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -