阅读:4377回复:6
打印驱动安装,AddPrinterDriver()失败???总结。。。
各位大虾:
关于打印驱动的用程序安装有很多的讨论文章,但最后一直没有一个明确的解决办法。让很多写这方面的朋友一直没有提高。 在这个论坛里讨论最多的一个帖子是: ----------------------------------------------------- http://www.driverdevelop.com/forum/html_44844.html?1071630540 文章标题 怎样把打印机驱动程序做成安装程序? ----------------------------------------------------- |
|
沙发#
发布于:2003-12-17 11:17
直接用程序写打印驱动的安装过程大概分2步:
1。添加一个打印驱动 主要使用AddPrinterDriver()函数 这一步的关键是什么???? 为什么我调用AddPrinterDriver()返回TRUE却没有真正装上驱动?? 怎样才算安装上了打印驱动? 2:添加打印机 主要使用AddPrinter()函数 这一步要成功的关键是指定的打印驱动必须存在 |
|
板凳#
发布于:2003-12-18 10:48
这是我安装过程的代码。
驱动安装文件手工安装可以完成的! //========================================================= PRINTER_INFO_2 pi2; DRIVER_INFO_3 di3; HANDLE hPrinter; char* Environment=_TEXT(\"Windows NT x86\"); char lpDriverPath[MAX_PATH]; char lpBuffer[MAX_PATH]; DWORD uSize=0; BOOL b=GetPrinterDriverDirectory(NULL,Environment,1,(LPBYTE)lpBuffer,MAX_PATH,&uSize); lstrcpy(_TEXT(lpDriverPath),_TEXT(lpBuffer)); lstrcat(_TEXT(lpDriverPath),_TEXT(\"\\\\VPrinter.dll\")); char lpDataFilePath[MAX_PATH]; lstrcpy(_TEXT(lpDataFilePath),_TEXT(lpBuffer)); lstrcat(_TEXT(lpDataFilePath),_TEXT(\"\\\\vprinter.GPD\")); char lpConfigFilePath[MAX_PATH]; lstrcpy(_TEXT(lpConfigFilePath),_TEXT(lpBuffer)); lstrcat(_TEXT(lpConfigFilePath),_TEXT(\"\\\\TVPproc.dll\")); char lpDependecy[MAX_PATH]; memset(lpDependecy,0,sizeof(lpDependecy)); lstrcat(lpDependecy,_TEXT(\"stdnames.gpd\\0VPRINTER.INF\\0\\0\")); ZeroMemory(&di3, sizeof(DRIVER_INFO_3)); di3.cVersion = 4; di3.pName =_TEXT(\"wookin Virtual Printer\");//HP LaserJet III di3.pEnvironment = Environment; di3.pDriverPath = lpDriverPath; di3.pDataFile =lpDataFilePath; di3.pConfigFile =lpConfigFilePath; di3.pDependentFiles = lpDependecy; di3.pHelpFile = NULL; di3.pMonitorName = NULL; di3.pDefaultDataType = _TEXT(\"RAW\"); b=AddPrinterDriver(NULL, 3, (LPBYTE)&di3); ZeroMemory(&pi2, sizeof(PRINTER_INFO_2)); pi2.pServerName=NULL; pi2.pPrinterName = _TEXT(\"xxx1\"); pi2.pPortName = _TEXT(\"LPT1:\"); pi2.pDriverName = _TEXT(\"Virtual Printer\"); //驱动一定要存在才可以 pi2.pPrintProcessor = _TEXT(\"WinPrint\"); pi2.pDatatype = _TEXT(\"RAW\"); pi2.AveragePPM = 400; hPrinter = AddPrinter(NULL, 2, (LPBYTE)&pi2); DWORD dwerr=GetLastError(); ClosePrinter(hPrinter); //========================================================= |
|
地板#
发布于:2004-04-09 09:05
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); |
|
|
地下室#
发布于:2004-04-09 09:07
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); |
|
|
5楼#
发布于:2004-04-09 09:09
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); |
|
|
6楼#
发布于:2009-11-08 21:58
怎么会这样啊
![]() |
|