阅读:1882回复:1
做Win2000的虚拟打印机.....
怎么使用AddPrinterDriver添加驱动?我的程序如下:
DRIVER_INFO_3 di3; char *lpBuffer=new char[MAX_PATH]; char *lpDriverPath=new char[MAX_PATH]; char *lpDataFilePath=new char[MAX_PATH]; char *lpConfigFilePath=new char[MAX_PATH]; char *lpDependecy=new char[MAX_PATH]; DWORD uSize; GetPrinterDriverDirectory(NULL,\"Windows NT x86\",1,(LPBYTE)lpBuffer,150,&uSize); lstrcpy(_TEXT(lpDriverPath),_TEXT(lpBuffer)); lstrcat(_TEXT(lpDriverPath),_TEXT(\"\\\\vprinter.dll\")); lstrcpy(_TEXT(lpDataFilePath),_TEXT(lpBuffer)); lstrcat(_TEXT(lpDataFilePath),_TEXT(\"\\\\vprinter.GPD\")); lstrcpy(_TEXT(lpConfigFilePath),_TEXT(lpBuffer)); lstrcat(_TEXT(lpConfigFilePath),_TEXT(\"\\\\vprinter.inf\")); lstrcat(lpDependecy,_TEXT(\"stdnames.gpd\\0vprinter.dll\\0vprinter.GPD\\0vprinter.inf\\0\\0\")); ZeroMemory(&di3, sizeof(DRIVER_INFO_3)); di3.cVersion = 3; di3.pName =_TEXT(\"Virtual Printer\");//HP LaserJet III di3.pEnvironment = Environment; di3.pEnvironment =_TEXT(\"Windows NT x86\"); di3.pDriverPath = lpDriverPath; di3.pDataFile =lpDataFilePath; di3.pConfigFile =lpConfigFilePath; di3.pDependentFiles = lpDependecy; di3.pHelpFile = NULL; di3.pMonitorName = NULL; di3.pDefaultDataType = _TEXT(\"RAW\"); AddPrinterDriver(NULL, 3, (LPBYTE)&di3); 运行没有结果,还望大家帮帮忙,谢谢了! |
|
沙发#
发布于:2004-04-09 09:28
Pointer to a null-terminated string that specifies the files the driver depends on. Each file name in the string is also terminated with a null (for example, Pscript.dll\\0Qms810.PPD\\0Pscrptui.dll\\0Pspcriptui.hlp\\0Pstest.txt\\0\\0). MSDN说这些字符串要紧凑的存储在内存里,每个文件都要用结束符来隔开,解决这个问题可以用下面的代码:
char *q = lpDependecy; lstrcpy(q, _T("file1.dll")); q += lstrlen(_T("file1.dll"))+1; lstrcpy(q, _T("file2.gpd")); q += lstrlen(_T("file2.gpd"))+1; lstrcpy(q, _T("file3.ini")); q += lstrlen(_T("file3.ini"))+1; lstrcpy(q, _T("file4.dll")); q += lstrlen(_T("file4.dll"))+1; lstrcpy(q, _T("file5.inf")); q += lstrlen(_T("file5.inf"))+1; 不过头疼的是,就算是这样,打印机还是不可以加上。不知道哪位高手可以赐教。我xp下的代码如下:请高手指点 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); str.Format("lpBuffer is %s\\n",lpBuffer); AfxMessageBox(str); 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")); memset(lpDependecy,0,sizeof(lpDependecy)); lstrcat(lpDependecy,_TEXT("Unires.dll\\0Stdname.gpd\\0Dragon.ini\\0Dragon.dll\\0Dragon.inf\\0\\0")); char *q = lpDependecy; lstrcpy(q, _T("Unires.dll")); q += lstrlen(_T("Unires.dll"))+1; lstrcpy(q, _T("Stdname.gpd")); q += lstrlen(_T("Stdname.gpd"))+1; lstrcpy(q, _T("Dragon.ini")); q += lstrlen(_T("Dragon.ini"))+1; lstrcpy(q, _T("Dragon.dll")); q += lstrlen(_T("Dragon.dll"))+1; lstrcpy(q, _T("Dragon.inf")); q += lstrlen(_T("Dragon.inf"))+1; 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 = lpDependecy; 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接口的。不知道还要在注册表里写些什么东东,请高手赐教指点,谢谢了!斑竹呀,这里有很多这方面的讨论,可惜没有一个是完全的,所以很多人碰到这些问题时,没有一个是可以解决的。能否整理一下这方面的知识点呢,或把代码发放出来,我相信有很多人都会感谢你的!!! |
|
|