阅读:2284回复:1
usb端口打印机安装的实现方法和注册表关系
有哪位高手知道安装usb端口打印机的实现方法和注册表关系么????当用下面代码安装后还需要在注册表里写些什么东西么?
PRINTER_INFO_2 pi2; DRIVER_INFO_3 di3; HANDLE hPrinter; char* Environment=_TEXT(\"Windows NT x86\"); char lpBuffer[MAX_PATH]; char lpDriverPath[MAX_PATH]; char lpDataFilePath[MAX_PATH]; char lpConfigFilePath[MAX_PATH]; char lpHelpFilePath[MAX_PATH]; char lpDependecy[MAX_PATH]; DWORD uSize=0; CString str; DWORD dwErr; BOOL b; char buffer[1024]; if (OpenPrinter(\"DRoad USB Printer\",&hPrinter,NULL)) { DeletePrinter(hPrinter); ClosePrinter(hPrinter); } DeletePrinterDriver(NULL,\"Windows NT x86\",\"DRoad USB Printer\"); GetPrinterDriverDirectory(NULL,Environment,1,(LPBYTE)lpBuffer,MAX_PATH,&uSize); lstrcpy(_TEXT(lpDriverPath),_TEXT(lpBuffer)); lstrcat(_TEXT(lpDriverPath),_TEXT(\"\\\\UNIDRV.DLL\")); lstrcpy(_TEXT(lpDataFilePath),_TEXT(lpBuffer)); lstrcat(_TEXT(lpDataFilePath),_TEXT(\"\\\\Dragon.GPD\")); lstrcpy(_TEXT(lpConfigFilePath),_TEXT(lpBuffer)); lstrcat(_TEXT(lpConfigFilePath),_TEXT(\"\\\\UNIDRVUI.DLL\")); lstrcpy(_TEXT(lpHelpFilePath),_TEXT(lpBuffer)); lstrcat(_TEXT(lpHelpFilePath),_TEXT(\"\\\\UNIDRV.HLP\")); ZeroMemory(&di3, sizeof(DRIVER_INFO_3)); di3.cVersion = 0x03; di3.pName =_TEXT(\"DRoad USB Printer\"); di3.pEnvironment = Environment; di3.pDriverPath = lpDriverPath; di3.pDataFile =lpDataFilePath; di3.pConfigFile =lpConfigFilePath; di3.pDependentFiles = \"Unires.dll\\0Stdname.gpd\\0Dragon.ini\\0Dragon.dll\\0dragon.inf\\0\\0\"; di3.pHelpFile = lpHelpFilePath; di3.pMonitorName = NULL; di3.pDefaultDataType = _TEXT(\"RAW\"); SetLastError(0); if (!AddPrinterDriver(NULL, 3, (LPBYTE)&di3)) { dwErr = GetLastError(); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,dwErr,NULL,buffer,sizeof(buffer),NULL); MessageBox(buffer); } ZeroMemory(&pi2, sizeof(PRINTER_INFO_2)); pi2.pServerName=NULL; pi2.pPrinterName = _TEXT(\"DRoad USB Printer\"); pi2.pPortName = _TEXT(\"USB001\"); pi2.pDriverName = _TEXT(\"DRoad USB Printer\"); pi2.pPrintProcessor = _TEXT(\"WinPrint\"); pi2.pDatatype = _TEXT(\"RAW\"); pi2.AveragePPM = 18; SetLastError(0); if ((hPrinter = AddPrinter(NULL, 2, (LPBYTE)&pi2))==NULL) { dwErr = GetLastError(); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,dwErr, NULL,buffer,sizeof(buffer),NULL); MessageBox(buffer); } ClosePrinter(hPrinter); 头疼的还有,运行时addprinterdriver经常失败,GetLastError返回2,说系统找不到指定的文件。而如果在运行addprinterdriver之前用手工或用installshield把所有有关于驱动的文件都拷贝到GetPrinterDriverDirectory返回的目录下而且要拷贝到3的目录下,那么就不会出现这个问题了。可是addprinter成功后。这时去看打印机是否安装上了,很高兴的是安装上了,不过头疼的还有一个问题就是,当我把打印机再次插拔时,系统又提示说找到一个硬件,然后弹出硬件安装向导。这说明我的打印机根本没有安装成功。我的打印机是usb接口的。不知道还要在注册表里写些什么东东,请高手赐教指点,谢谢了!斑竹呀,这里有很多这方面的讨论,可惜没有一个是完全的,所以很多人碰到这些问题时,没有一个是可以解决的。能否整理一下这方面的知识点呢,或把代码发放出来,我相信有很多人都会感谢你的!!! |
|
|
沙发#
发布于:2004-04-28 14:49
怎么没有人回复的呀,不过问题俺已经解决。自己也顶一下。。。呵呵
|
|
|