📄 string.c
字号:
/// Note: This function is not implemented for this particular driver
///
/// Parameters:
/// \param pOpenContext Handle to the open context of the device. The <b>STR_Open</b>
/// (Device Manager) function creates and returns this identifier.
/// \param pBuffer Pointer to the buffer that stores the data read from
/// the device. This buffer should be at least <i>Count</i> bytes long.
/// \param dwCount Number of bytes to read from the device into <i>pBuffer</i>.
///
/// \return \e zero to indicate <i>end-of-file</i>.
/// \return \e -1 to indicate an error.
/// \return The number of bytes read to indicate success.
///
////////////////////////////////////////////////////////////////////////////////
DWORD STR_Read(void *pOpenContext, LPVOID pBuffer, DWORD dwCount)
{
// This function is not used by this driver
return -1;
}
////////////////////////////////////////////////////////////////////////////////
/// This function writes data to the device.
/// After an application uses the WriteFile function to write to the device, the operating system,
/// invokes this function. The <i>hFile</i> parameter is a handle to the device. The <i>pBuffer</i> parameter
/// points to the buffer that contains the data read from the device. The <i>dwCount</i> parameter indicates
/// the number of bytes that the application requests to write to the device.
///
/// Parameters:
/// \param pOpenContext Handle to the open context of the device. The <b>STR_Open</b>
/// (Device Manager) function creates and returns this identifier.
/// \param pBuffer Pointer to the buffer that contains the data to write.
/// This buffer should be at least <i>Count</i> bytes long.
/// \param dwCount Number of bytes to write from the <i>pBuffer</i> buffer into the device.
///
/// \return The number of bytes written indicates success
/// \return \e -1 to indicate an error.
///
////////////////////////////////////////////////////////////////////////////////
DWORD STR_Write(void *pOpenContext, LPCVOID pBuffer, DWORD dwCount)
{
// This function is not used by this driver
return -1;
}
////////////////////////////////////////////////////////////////////////////////
/// This function moves the data pointer in the device.
/// After an application calls the SetFilePointer function to move the data pointer in the device,
/// the operating system invokes this function. If your device is capable of opening more than once,
/// this function modifies only the data pointer for the instance specified by <i>pOpenContext</i>.
///
/// Parameters
/// \param pOpenContext Handle to the open context of the device. The <b>STR_Open</b>
/// (Device Manager) function creates and returns this identifier.
/// \param Amount Number of bytes to move the data pointer in the device. A positive value
/// moves the data pointer toward the end of the file and a negative value
/// moves it toward the beginning.
/// \param wType Starting point for the data pointer. The following table shows the available values for this parameter.
///
/// \return The new data pointer for the device indicates success.
/// \return \e -1 to indicate an error.
///
////////////////////////////////////////////////////////////////////////////////
DWORD STR_Seek(void *pOpenContext, long Amount, WORD wType)
{
// This function is not used
return -1;
}
////////////////////////////////////////////////////////////////////////////////
/// This function sends a command to a device.
/// An application uses the DeviceIoControl function to specify an operation to perform. The operating system,
/// in turn, invokes the <b>STR_IOControl</b> function. The <i>dwCode</i> parameter contains the input or output
/// operation to perform; these codes are usually specific to each device driver and are exposed to application
/// programmers through a header file that the device driver developer makes available.
///
/// Parameters:
/// \param pOpenContext Handle to the open context of the device. The <b>STR_Open</b>
/// (Device Manager) function creates and returns this identifier.
/// \param dwCode I/O control operation to perform. These codes are device-specific and
/// are usually exposed to developers through a header file.
/// Use <b>CTL_CODE</b> macro to generate a driver unique identifier for your iocontrol.
/// \param pBufIn Pointer to the buffer containing data to transfer to the device.
/// \param dwLenIn Number of bytes of data in the buffer specified for <i>pBufIn</i>.
/// \param pBufOut Pointer to the buffer used to transfer the output data from the device.
/// \param dwLenOut Maximum number of bytes in the buffer specified by <i>pBufOut</i>.
/// \param pdwActualOut Pointer to the <b>DWORD</b> buffer that this function uses to
/// return the actual number of bytes received from the device.
///
/// \return \e TRUE indicates success.
/// \return \e FALSE indicates failure.
///
////////////////////////////////////////////////////////////////////////////////
BOOL STR_IOControl(void *pOpenContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut)
{
T_DRIVEROPEN_STRUCTURE* pExplicitOpenContext;
// The device has to be open
if (pOpenContext == NULL)
return FALSE;
pExplicitOpenContext = (T_DRIVEROPEN_STRUCTURE *)pOpenContext;
//Something has gone wrong if the device says there are no contexts open
if (pExplicitOpenContext->pDeviceContext->dwOpenCount == 0)
return FALSE;
DEBUGMSG(ZONE_IOCTL,(L"STRING: IOCTL, code:%d\n", dwCode));
switch (dwCode)
{
case IOCTL_POWER_CAPABILITIES:
if (pBufOut != NULL && dwLenOut == sizeof(POWER_CAPABILITIES))
{
PPOWER_CAPABILITIES ppc = (PPOWER_CAPABILITIES) pBufOut;
memset(ppc, 0, sizeof(*ppc));
// support D0,D1,D2,D3 and D4
ppc->DeviceDx = (1<<D0) | (1<<D1) | (1<<D2) | (1<<D3) | (1<<D4);
*pdwActualOut = sizeof(POWER_CAPABILITIES);
DEBUGMSG(ZONE_IOCTL, (L"STRING: IOCTL_POWER_CAPABILITIES"));
}
break;
case IOCTL_POWER_QUERY:
if(pBufOut != NULL && dwLenOut == sizeof(CEDEVICE_POWER_STATE))
{
// return a good status on any valid query, since we are always ready to
// change power states.
CEDEVICE_POWER_STATE NewDx = *(PCEDEVICE_POWER_STATE) pBufOut;
DEBUGMSG(ZONE_IOCTL, (L"STRING: IOCTL_POWER_QUERY"));
if(!VALID_DX(NewDx))
{
return FALSE;
}
}
break;
case IOCTL_POWER_SET:
if(pBufOut != NULL && dwLenOut == sizeof(CEDEVICE_POWER_STATE))
{
CEDEVICE_POWER_STATE NewDx = *(PCEDEVICE_POWER_STATE) pBufOut;
if(VALID_DX(NewDx))
{
DEBUGMSG(ZONE_IOCTL, (L"STRING: IOCTL_POWER_SET to state %d",
NewDx));
pExplicitOpenContext->CurrentDx = NewDx;
}
}
break;
case IOCTL_POWER_GET:
if(pBufOut != NULL && dwLenOut == sizeof(CEDEVICE_POWER_STATE))
{
*(PCEDEVICE_POWER_STATE) pBufOut = pExplicitOpenContext->CurrentDx;
*pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
DEBUGMSG(ZONE_IOCTL, (L"STRING: IOCTL_POWER_GET, returning %d",
pExplicitOpenContext->CurrentDx));
}
break;
case IOCTL_STRING_SET:
//Check for validity of input buffer
if (pBufIn == NULL || dwLenIn != sizeof(PARMS_STRING))//Check all the input parameters
{
SetLastError(ERROR_INVALID_PARAMETER);
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR,(L"STRING: IOCTL_STRING_SET: ERROR: INVALID PARAMETERS\n", dwCode));
return FALSE;
}
else
{
DEBUGMSG(ZONE_IOCTL,(L"IOCTL_STRING_SET\n"));
if (0 ==
wcscpy_s(
pExplicitOpenContext->szStoredString,
STR_MAX_STRING_LENGTH,
( (PARMS_STRING*) pBufIn )->szString
)
)
{
DEBUGMSG(ZONE_IOCTL, (L"Stored string \"%s\" successfully", pExplicitOpenContext->szStoredString));
}
else
{
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (L"Error storing string"));
return FALSE;
}
}
break;
case IOCTL_STRING_CLEAR:
//Check for validity of input buffer
if (pBufIn != NULL || dwLenIn != 0) //Check all the input parameters
{
SetLastError(ERROR_INVALID_PARAMETER);
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR,(L"STRING: IOCTL_STRING_CLEAR: ERROR: INVALID PARAMETERS\n", dwCode));
return FALSE;
}
else
{
DEBUGMSG(ZONE_IOCTL,(L"IOCTL_STRING_CLEAR\n"));
memset(pExplicitOpenContext->szStoredString, 0, sizeof(TCHAR)*STR_MAX_STRING_LENGTH);
}
break;
case IOCTL_STRING_READ:
//Check for validity of input buffer
if (pBufIn != NULL ||
dwLenIn != 0 ||
pBufOut == NULL ||
dwLenOut != sizeof(PARMS_STRING)
)//Check all the input parameters
{
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR,(L"STRING: IOCTL_STRING_READ: ERROR: INVALID PARAMETERS\n", dwCode));
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
DEBUGMSG(ZONE_IOCTL,(L"IOCTL_STRING_READ\n"));
if (0 ==
wcscpy_s(
( (PARMS_STRING*) pBufOut )->szString,
STR_MAX_STRING_LENGTH,
pExplicitOpenContext->szStoredString
)
)
{
DEBUGMSG(ZONE_IOCTL, (L"Stored string \"%s\" successfully copied to output buffer", pExplicitOpenContext->szStoredString));
}
else
{
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (L"Error retrieving string"));
return FALSE;
}
if (pdwActualOut != NULL)
*pdwActualOut = sizeof(PARMS_STRING);
break;
default:
SetLastError(ERROR_INVALID_CATEGORY);
return FALSE;
}
return TRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// This function suspends power to the device. It is useful only with devices that can
/// power down under software control. Such devices are typically, but not exclusively, PC Cards.
/// The OS invokes this function to suspend power to a device.
///
/// WARNING: During this call, the processor is running in single threaded mode and most
/// system calls are disabled. Do not attempt to make external calls, page memory, or generate
/// any exceptions in this function!
///
/// Parameters:
/// \brief
/// \param pDeviceContext Pointer to the device context. The call to the <b>STR_Init</b>
/// (Device Manager) function returns this identifier.
///
////////////////////////////////////////////////////////////////////////////////
void STR_PowerDown(void *pDeviceContext)
{
}
////////////////////////////////////////////////////////////////////////////////
/// This function restores power to a device.
/// The OS invokes this function to restore power to a device.
///
/// WARNING: During this call, the processor is running in single threaded mode and most
/// system calls are disabled. Do not attempt to make external calls, page memory, or generate
/// any exceptions in this function!
///
/// Parameters:
/// \param pDeviceContext Pointer to the device context. The call to the <b>STR_Init</b>
/// (Device Manager) function returns this identifier.
///
////////////////////////////////////////////////////////////////////////////////
void STR_PowerUp(void *pDeviceContext)
{
}
////////////////////////////////////////////////////////////////////////////////
// Internal functions
////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -