20楼#
发布于:2003-05-17 08:45
我已成功了,我把代码发给各位参考吧:
HANDLE GetDeviceViaInterface( GUID* pGuid, DWORD instance); extern GUID DriverPrint= { 0xaba1121c, 0xebfb, 0x4796, { 0xb5, 0xbb, 0xd1, 0xb6, 0xc7, 0xf9, 0x8, 0xdc } }; //extern GUID DriverPrint= { 0x87472ba0, 0x61bc, 0x11d2, 0xb6, 0x77, 0x0, 0xc0, 0xdf, 0xe4, 0xc1, 0xf3}; /*HANDLE OpenByInterface( GUID pClassGuid, DWORD instance, PDWORD pError ) { HANDLE hDev; CDeviceInterfaceClass DevClass(&pClassGuid,pError); // if(*pError!=ERROR_SUCCESS) // return INVALID_HANDLE_VALUE; CDeviceInterface DevInterface(&DevClass,instance,pError); // if(*pError!=ERROR_SUCCESS) // return INVALID_HANDLE_VALUE; hDev=CreateFile( DevInterface.DevicePath(), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); DWORD d=GetLastError(); //2 The system cannot find the file specified. // Add \"About...\" menu item to system menu. //3 The system cannot find the path specified. ERROR_PATH_NOT_FOUND // if(hDev==INVALID_HANDLE_VALUE) // *pError=GetLastError(); return hDev; } */ HANDLE GetDeviceViaInterface( GUID* pGuid, DWORD instance) { // Get handle to relevant device information set HDEVINFO info = SetupDiGetClassDevs(pGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); if(info==INVALID_HANDLE_VALUE) { printf(\"No HDEVINFO available for this GUID\\n\"); return NULL; } // Get interface data for the requested instance SP_INTERFACE_DEVICE_DATA ifdata; ifdata.cbSize = sizeof(ifdata); if(!SetupDiEnumDeviceInterfaces(info, NULL, pGuid, instance, &ifdata)) { printf(\"No SP_INTERFACE_DEVICE_DATA available for this GUID instance\\n\"); SetupDiDestroyDeviceInfoList(info); return NULL; } // Get size of symbolic link name DWORD ReqLen; SetupDiGetDeviceInterfaceDetail(info, &ifdata, NULL, 0, &ReqLen, NULL); PSP_INTERFACE_DEVICE_DETAIL_DATA ifDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)(new char[ReqLen]); if( ifDetail==NULL) { SetupDiDestroyDeviceInfoList(info); return NULL; } // Get symbolic link name ifDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA); if( !SetupDiGetDeviceInterfaceDetail(info, &ifdata, ifDetail, ReqLen, NULL, NULL)) { SetupDiDestroyDeviceInfoList(info); delete ifDetail; return NULL; } printf(\"Symbolic link is %s\\n\",ifDetail->DevicePath); // Open file HANDLE rv = CreateFile( ifDetail->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL); delete ifDetail; SetupDiDestroyDeviceInfoList(info); return rv; } class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTestCKPDriverDlg dialog CTestCKPDriverDlg::CTestCKPDriverDlg(CWnd* pParent /*=NULL*/) : CDialog(CTestCKPDriverDlg::IDD, pParent) { //{{AFX_DATA_INIT(CTestCKPDriverDlg) m_strList = _T(\"\"); m_lgRange = 0; m_ulOffset = 0; m_ulStart = 0; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CTestCKPDriverDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTestCKPDriverDlg) DDX_Control(pDX, IDC_EDIT_OFFSET, m_conOffset); DDX_Control(pDX, IDC_RADIO_READ, m_conRead); DDX_Control(pDX, IDC_RADIO_BASE8, m_cbuttonRadio); DDX_Control(pDX, IDC_EDIT_START, m_conStart); DDX_Control(pDX, IDC_EDIT_RANGE, m_conRange); DDX_Control(pDX, IDC_EDIT_LIST, m_conList); DDX_Text(pDX, IDC_EDIT_LIST, m_strList); DDX_Text(pDX, IDC_EDIT_RANGE, m_lgRange); DDX_Text(pDX, IDC_EDIT_OFFSET, m_ulOffset); DDX_Text(pDX, IDC_EDIT_START, m_ulStart); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CTestCKPDriverDlg, CDialog) //{{AFX_MSG_MAP(CTestCKPDriverDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear) ON_BN_CLICKED(IDC_BUTTON_APPLY, OnButtonApply) ON_BN_CLICKED(IDC_RADIO_BASE8, OnRadioBase8) ON_BN_CLICKED(IDC_RADIO_BASE32, OnRadioBase32) ON_BN_CLICKED(IDC_RADIO_READ, OnRadioRead) ON_BN_CLICKED(IDC_RADIO_WRITE, OnRadioWrite) ON_BN_CLICKED(IDC_RADIO_SEARCH, OnRadioSearch) ON_BN_CLICKED(IDEXIT, OnExit) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTestCKPDriverDlg message handlers BOOL CTestCKPDriverDlg::OnInitDialog() { CDialog::OnInitDialog(); //初始化单选按钮 m_uiCommand=1; m_uiMemory=1; m_ulStart=0; m_cbuttonRadio.SetCheck(1); m_conRead.SetCheck(1); DWORD instance=1; PDWORD pError=NULL; /* hCom=CreateFile( \"\\\\\\.\\\\SWPrintDevice0\", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );*/ GUID* pGuid=(GUID*)&DriverPrint; DWORD instance1=0; hCom=GetDeviceViaInterface( pGuid,instance1); DWORD d=GetLastError(); // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application\'s main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE);// Set small icon return TRUE; // return TRUE unless you set the focus to a control } void CTestCKPDriverDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CTestCKPDriverDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CTestCKPDriverDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CTestCKPDriverDlg::OnButtonClear() { m_strList=\" \"; UpdateData(false); } void CTestCKPDriverDlg::OnOK() { // TODO: Add extra validation here CDialog::OnOK(); } void CTestCKPDriverDlg::OnButtonApply() { UpdateData(true); DWORD lpNumberOfBytesInPut=0; seBuffer[0]=m_uiCommand*16+m_uiMemory; seBuffer[1]=m_ulStart; seBuffer[2]=m_ulOffset; seBuffer[3]=m_lgRange; BOOL status=WriteFile(hCom ,&seBuffer,4,&lpNumberOfBytesInPut,NULL); if(!status) return; DWORD lpNumberOfBytesRead ; BOOL staus=ReadFile(hCom, &reBuffer,4,&lpNumberOfBytesRead,NULL); switch(m_uiCommand) { case 1: { // LPDWORD lpNumberOfBytesRead=NULL; // pointer to number of bytes read // BOOL staus=ReadFile(hCom, &reBuffer[0],4,lpNumberOfBytesRead,NULL); //dEorror=GetLastError(); readData(); break; } case 2: { LPDWORD lpNumberOfBytesWrite=NULL; // pointer to number of bytes read writeData(); // BOOL staus=WriteFile(hCom,seBuffer,256,lpNumberOfBytesWrite,NULL); break; } case 3: ;break; } UpdateData(false); } void CTestCKPDriverDlg::readData() { m_strList.Empty( ); m_strList=(UCHAR)reBuffer; m_strList.Format(\"%c\"); m_strList+=\"reciev data) !\"; UpdateData(false); } void CTestCKPDriverDlg::writeData() { m_strList.Empty( ); UpdateData(true); m_strList.Format(\"%c\"); m_strList+=\"Sent data!\"; // for(int i=0;i<m_strList.GetLength();i++) // seBuffer=m_strList.GetAt(i); } void CTestCKPDriverDlg::OnRadioBase8() { m_uiMemory=1; } void CTestCKPDriverDlg::OnRadioBase32() { m_uiMemory=2; } void CTestCKPDriverDlg::OnRadioRead() { m_uiCommand=1; } void CTestCKPDriverDlg::OnRadioWrite() { m_uiCommand=2; } void CTestCKPDriverDlg::OnRadioSearch() { m_uiCommand=3; } void CTestCKPDriverDlg::OnExit() { CDialog::OnCancel(); } |
|
21楼#
发布于:2003-05-17 08:48
还有两个类,有兴趣的同我联系
Email:sunnyflyfox@163.com |
|
22楼#
发布于:2003-05-17 13:11
谢谢,各位了 是这样一个过程:应用程序中有个DEVICEIOCONTROL函数,当调用它时,相当于在驱动程序中调用ONWIN32DEVICEIOCONTROL函数,在应用程序的DEVICEIOCONTROL函数中有个控制代码可以控制驱动程序的工作 |
|
23楼#
发布于:2003-05-17 13:18
[quote]谢谢,各位了 是这样一个过程:应用程序中有个DEVICEIOCONTROL函数,当调用它时,相当于在驱动程序中调用ONWIN32DEVICEIOCONTROL函数,在应用程序的DEVICEIOCONTROL函数中有个控制代码可以控制驱动程序的工作 [/quote] 这是vxd的。 |
|
24楼#
发布于:2003-05-17 13:22
Sorry,我只做过VXD的,别的不知道了
|
|
25楼#
发布于:2003-05-18 22:24
windows wdm设备驱动程序开发指南一书上说的很清楚,也有相应的例子,我试过,可以的,但他只能出现一个32位的dos窗口,我想把他做成win界面下的,可调用hWdm1 = GetDeviceViaInterface((LPGUID)&WDM1_GUID, 0);时编译就不能通过,说是redefine了,哪位做过的前辈来指导一下了.有同样困难的也可以一起探讨.
email:yxp@qixiangc.com. qq:17171109 |
|
|
26楼#
发布于:2003-05-19 11:24
看你的说法,是不是用的windriver?
如果是回个话,我可以告诉你。 |
|
|
27楼#
发布于:2003-05-21 11:53
windows wdm设备驱动程序开发指南一书上说的很清楚,也有相应的例子,我试过,可以的,但他只能出现一个32位的dos窗口,我想把他做成win界面下的,可调用hWdm1 = GetDeviceViaInterface((LPGUID)&WDM1_GUID, 0);时编译就不能通过,说是redefine了,哪位做过的前辈来指导一下了.有同样困难的也可以一起探讨. 你把guid换个值试试 :) |
|
|
上一页
下一页