//
// FirstSysApp.cpp : Defines the entry point for the application.
//
// Generated by C DriverWizard 3.2.0 (Build 2485)
// Requires DDK Only
// File created on 10/15/2009
//
#include "FirstSysApp.h"
// Array of possible transfer types
PTCHAR g_TransferTypeArray[] =
{
_T("ReadFile"),
_T("WriteFile"),
_T("")
};
HANDLE g_hDevice = INVALID_HANDLE_VALUE;
HDEVNOTIFY g_hInterfaceNotification = NULL;
FIRSTSYS_LIST_ITEM g_IoList;
CRITICAL_SECTION g_IoListLock;
HANDLE g_hIoCompletionThreadTerminationEvent;
HANDLE g_hIoCompletionThread;
///////////////////////////////////////////////////////////////////////////////////////////////////
// FirstSysOutputText
// method to output text in the output window
//
// Arguments:
// IN Format
// Text format to print to output window
//
// Return Value:
// None.
//
VOID FirstSysOutputText(LPCTSTR Format, ...)
{
TCHAR str[MAX_STRING_LENGTH];
va_list vaList;
va_start(vaList, Format);
_vstprintf(str, Format, vaList);
OutputDebugString(_T("FirstSys: "));
OutputDebugString(str);
OutputDebugString(_T("\n"));
va_end(vaList);
return;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// FirstSysOutputBuffer
// method to output text in the output window
//
// Arguments:
// IN Buffer
// Data Buffer
//
// IN Size
// Size of Data Buffer
//
// Return Value:
// None.
//
VOID FirstSysOutputBuffer(PVOID Buffer, ULONG Size)
{
TCHAR str[MAX_STRING_LENGTH];
LONG length = (LONG)Size;
PUCHAR p = (PUCHAR)Buffer;
TCHAR data[MAX_STRING_LENGTH];
TCHAR rawData[MAX_STRING_LENGTH];
ULONG i;
ULONG j;
for (i = 0; i < Size; i += 16)
{
ZeroMemory(str, sizeof(str));
ZeroMemory(rawData, sizeof(rawData));
_stprintf(str, _T("%04.4X "), i);
for (j = 0; j < 16; ++j, ++p)
{
if (length > 0)
{
_stprintf(data, _T("%02X "), *p);
}
else
{
_stprintf(data, _T(" "));
}
_tcsncat(str, data, 3);
if (length > 0)
{
TCHAR c = (TCHAR)(*p);
if (_istalnum(_TUCHAR(c)))
{
_stprintf(data, _T("%c"), c);
}
else
{
_tcsncat(rawData, _T("?"), 1);
}
--length;
}
}
_tcsncat(str, _T(" "), 2);
_tcsncat(str, rawData, 16);
OutputDebugString(str);
OutputDebugString(_T("\n"));
}
return;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// FirstSysEnumerateDevices
// Finds devices associated with the given interface class
//
// Arguments:
// IN hDlg
// Handle to dialog
//
// Return Value:
// status.
//
DWORD FirstSysEnumerateDevices(HWND hDlg)
{
HWND hList;
DWORD lastError;
LONG ii = 0;
HDEVINFO hDeviceInfo;
DWORD bufferSize;
SP_DEVICE_INTERFACE_DATA interfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA deviceDetail;
// Get the handle to the device instance list box
hList = GetDlgItem(hDlg, IDC_DEVICE_INSTANCE_LIST);
if (hList == NULL)
{
lastError = GetLastError();
FirstSysOutputText(_T("GetDlgItem failed, GetLastError() = %d"), lastError);
return lastError;
}
// Clear the instance list box
SendMessage(hList, LB_RESETCONTENT, 0, 0);
// Find all devices that have our interface
hDeviceInfo = SetupDiGetClassDevs(
(LPGUID)&GUID_DEVINTERFACE_FIRSTSYS,
NULL,
NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE
);
if (hDeviceInfo == INVALID_HANDLE_VALUE)
{
lastError = GetLastError();
FirstSysOutputText(_T("SetupDiGetClassDevs failed, GetLastError() = %d"), lastError);
return lastError;
}
// Setup the interface data struct
interfaceData.cbSize = sizeof(interfaceData);
for (ii = 0;
SetupDiEnumDeviceInterfaces(
hDeviceInfo,
NULL,
(LPGUID)&GUID_DEVINTERFACE_FIRSTSYS,
ii,
&interfaceData);
++ii)
{
// Found our device instance
if (!SetupDiGetDeviceInterfaceDetail(
hDeviceInfo,
&interfaceData,
NULL,
0,
&bufferSize,
NULL))
{
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
FirstSysOutputText(_T("Error: couldn't get interface detail, (%d)"), GetLastError());
continue;
}
}
// Allocate a big enough buffer to get detail data
deviceDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(bufferSize);
if (deviceDetail == NULL)
{
FirstSysOutputText(_T("Error: Buffer allocation failed"));
continue;
}
// Setup the device interface struct
deviceDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
// Try again to get the device interface detail info
if (!SetupDiGetDeviceInterfaceDetail(
hDeviceInfo,
&interfaceData,
deviceDetail,
bufferSize,
NULL,
NULL))
{
FirstSysOutputText(_T("Error: SetupDiGetDeviceInterfaceDetail failed (%d)"), GetLastError());
free(deviceDetail);
continue;
}
// Add device instance info to list
SendMessage(
hList,
LB_ADDSTRING,
0,
(LPARAM)deviceDetail->DevicePath
);
// Free our allocated buffer
free(deviceDetail);
}
SetupDiDestroyDeviceInfoList(hDeviceInfo);
if (ii == 0)
{
FirstSysOutputText(_T("No devices found"));
}
return ERROR_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// FirstSysOpenDevice
// Opens the nth device found with the given interface class
//
// Arguments:
// IN hDlg
// Handle to dialog
//
// Return Value:
// Handle to device.
//
HANDLE FirstSysOpenDevice(HWND hDlg)
{
HWND hList;
HANDLE hDev;
TCHAR path[MAX_STRING_LENGTH];
DWORD itemIndex;
// Get handle to device instance list box
hList = GetDlgItem(hDlg, IDC_DEVICE_INSTANCE_LIST);
// Find the current selection
itemIndex = (DWORD)SendMessage(hList, LB_GETCURSEL, 0, 0);
// Get the path string from the list box
(LPTSTR)SendMessage(
hList,
LB_GETTEXT,
itemIndex,
(LPARAM)path);
// Open handle to device
hDev = CreateFile(
path,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
0
);
if (hDev == INVALID_HANDLE_VALUE)
{
FirstSysOutputText(_T("Error: CreateFile failed for device %s (
没有合适的资源?快使用搜索试试~ 我知道了~
驱动程序模板(VC++)
共33个文件
h:6个
cpp:4个
makefile:2个
需积分: 10 9 下载量 101 浏览量
2009-10-15
15:27:45
上传
评论
收藏 75KB RAR 举报
温馨提示
DriverStudio3.2+WindowS DDK2600+VC6.0环境生成的,内有已经生成的.SYS和.INF文件,可以直接在电脑上安装这个空白的驱动程序
资源推荐
资源详情
资源评论
收起资源包目录
driver.rar (33个子文件)
driver
FirstSys
dirs 35B
FirstSys.ncb 73KB
intrface.h 1KB
FirstSys.dsw 749B
driver
sources 2KB
function.h 726B
FirstSysDevice.h 2KB
FirstSysDriver.cpp 5KB
objfre
i386
FirstSys.sys 22KB
FirstSysDevice.obj 23KB
FirstSys.pdb 59KB
FirstSys.NMS 19KB
FirstSys.res 820B
FirstSysDriver.obj 13KB
FirstSys.plg 249B
makefile 267B
FirstSysDriver.h 703B
FirstSys.inf 4KB
FirstSys.rc 1KB
FirstSysDevice.cpp 18KB
FirstSys.cat 172B
FirstSys.dsp 6KB
app
sources 615B
resource.h 1KB
FirstSysApp.dsp 5KB
makefile 267B
FirstSysApp.cpp 19KB
FirstSysIorw.cpp 11KB
FirstSysApp.rc 2KB
FirstSysApp.h 1KB
FirstSysVars.xml 7KB
FirstSys.opt 59KB
ReadMe.htm 12KB
共 33 条
- 1
资源评论
asdaaassd
- 粉丝: 2
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功