阅读:1798回复:1
ComSpy安装失败,请各位老大多多指教
在本网站上下载据说是串口过滤驱动的源代码,ComSpy.rar。解压编译都可以但是安装的时候提示失败。
根据源代码调试发现: 安装成功了,下面的代码 if (m_hDevice!=INVALID_HANDLE_VALUE) return FALSE; /////////////////////////////////////////////////////////////////////////////////////// CHAR DriverFileName[80]; if (!GetSystemDirectory(DriverFileName, 55)) { return FALSE; } strcat(DriverFileName,"\\Drivers\\ComSpy.sys"); if (!CopyFile(".\\ComSpy.sys", DriverFileName, FALSE)) { return FALSE; } /////////////////////////////////////////////////////////////////////////////////////// SC_HANDLE sc=OpenSCManager(NULL,SERVICES_ACTIVE_DATABASE,SC_MANAGER_ALL_ACCESS); if (!sc) { AfxMessageBox(_T("You must have administrative priviledges to install device driver"),MB_OK); return FALSE; } CString s=DriverFileName; DWORD dwError = 0; SC_HANDLE hSrv; hSrv=CreateService(sc,_T("ComSpy"),_T("ComSpy"), SERVICE_ALL_ACCESS | GENERIC_EXECUTE | SERVICE_START | SERVICE_STOP, SERVICE_KERNEL_DRIVER,SERVICE_DEMAND_START,SERVICE_ERROR_IGNORE, s, NULL, NULL, NULL, NULL, NULL); CloseServiceHandle(sc); if (!hSrv) { AfxMessageBox(_T("Unexpected error. Cannot create service"),MB_OK); return FALSE; } if (!StartService(hSrv,0,NULL)) { dwError = GetLastError(); qq: AfxMessageBox(_T("Cannot start device. Sys maybe not found"),MB_OK); DeleteService(hSrv); CloseServiceHandle(hSrv); return FALSE; } CloseServiceHandle(hSrv); AfxMessageBox(_T("ComSpy device driver successfully installed"),MB_OK); 但是使用CreateFile打开\\\\.\\ComSpy时失败,不知道为什么? 另外,在此rar文件中还有一个Install文件夹,这是一个安装dll的文件夹,这个非常向安装过滤驱动的代码但是运行没有错误,找不到serial0这个设备所以安装不上,不知道这是为什么?使用winobj可以看到serial0这个设备 DWORD Ctransfer_drvDlg::InstallFilterDrv(LPCTSTR pszServiceName, LPCTSTR pszFilterPath) { DWORD status = ERROR_SUCCESS; char szWindowsDirectory[MAX_PATH] = ""; if (!GetWindowsDirectory(szWindowsDirectory, sizeof(szWindowsDirectory))) { status = GetLastError(); return status; } char *psztemp = strrchr(pszFilterPath,'\\'); if(psztemp == NULL) { return 1; } lstrcat(szWindowsDirectory, "\\System32\\Drivers"); lstrcat(szWindowsDirectory,psztemp); // Copy the driver file to system32/drivers if(!CopyFile(pszFilterPath, // name of an existing file szWindowsDirectory, // name of new file FALSE // operation if file exists )) { status = GetLastError(); return status; } status = AddService(pszServiceName, szWindowsDirectory); if ((status != ERROR_SUCCESS) && (status != ERROR_SERVICE_EXISTS)) { return status; } HDEVINFO hDevInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT); if (hDevInfo == INVALID_HANDLE_VALUE) { status = GetLastError(); return status; } SP_DEVINFO_DATA devInfoData = {sizeof(SP_DEVINFO_DATA)}; for (DWORD index = 0; SetupDiEnumDeviceInfo(hDevInfo, index, &devInfoData); ++index) { TCHAR devDesc[MAX_PATH]; DWORD nSize = 0; if (SetupDiGetDeviceRegistryProperty( hDevInfo, &devInfoData, SPDRP_DEVICEDESC, NULL, (PBYTE)&devDesc, sizeof(devDesc), &nSize) ) { if (_tcscmp(devDesc, _T("Serial0")) == 0) { TCHAR filters[MAX_PATH]; DWORD filtersLength = 0; if (SetupDiGetDeviceRegistryProperty( hDevInfo, &devInfoData, SPDRP_UPPERFILTERS, NULL, (PBYTE)filters, sizeof(filters), &filtersLength) ) { LPTSTR p = SearchMultiSz(filters, filtersLength, _T("comspy")); if (p == NULL) { _tcscpy(&filters[filtersLength/sizeof(TCHAR) - 1], _T("comspy")); filtersLength += (DWORD)_tcslen(_T("comspy"))*sizeof(TCHAR); filters[filtersLength/sizeof(TCHAR)] = 0; filters[filtersLength/sizeof(TCHAR) + 1] = 0; if (!SetupDiSetDeviceRegistryProperty( hDevInfo, &devInfoData, SPDRP_UPPERFILTERS, (PBYTE)filters, filtersLength + sizeof(TCHAR)) ) { status = GetLastError(); } } } else { status = GetLastError(); if (status == ERROR_INVALID_DATA) { status = ERROR_SUCCESS; _tcscpy(filters, _T("comspy")); filtersLength = (DWORD)_tcslen(_T("comspy"))*sizeof(TCHAR); filters[filtersLength/sizeof(TCHAR)] = 0; filters[filtersLength/sizeof(TCHAR) + 1] = 0; if (!SetupDiSetDeviceRegistryProperty( hDevInfo, &devInfoData, SPDRP_UPPERFILTERS, (PBYTE)filters, filtersLength + 2*sizeof(TCHAR)) ) { status = GetLastError(); } } } } } } SetupDiDestroyDeviceInfoList(hDevInfo); return status; } |
|
沙发#
发布于:2007-09-28 11:20
终于搞定了,本人犯了一愚蠢的错误
|
|