nErr=RegCreateKeyEx(HKEY_LOCAL_MACHINE,szRegKey,0,L"",0,0,NULL,&hDrvKey,&dwDisp); if(nErr!=ERROR_SUCCESS) { MessageBox(_T("创建驱动注册表子键失败!")); return; } else { //往注册表里添加内容 WRITE_REG_SZ(L"Prefix",szPrefix); WRITE_REG_SZ(L"Dll",szDLL); WRITE_REG_SZ(L"FriendlyName",szFriendlyName); WRITE_REG_DWORD(L"Order",DrvOrder); WRITE_REG_DWORD(L"Index",DrvIndex); } HandleDriver=ActivateDeviceEx(szRegKey,NULL,0,NULL); //加载SimpleDriver驱动 if(HandleDriver==INVALID_HANDLE_VALUE) { MessageBox(_T("加载SimpleDriver失败!")); } else { MessageBox(_T("加载SimpleDriver成功!")); } 并且成功了
hFile=CreateFile(_T("SPL1:"),GENERIC_READ|GENERIC_WRITE,0,0, OPEN_EXISTING,0,0); //sprintf(buf,"hFile=0x%x",hFile); CString strTmp; strTmp.Format(_T("%x"),hFile); CEdit *pDispEdit=(CEdit*)GetDlgItem(IDC_READ_DISP); pDispEdit->SetWindowText(strTmp); if(hFile==INVALID_HANDLE_VALUE) { MessageBox(_T("不能打开")); } else { MessageBox(_T("打开成功!")); } 打开驱动时,却总是失败 |