我编写了一个可在x86和x64 MS Windows系统下运行的打印机驱动程序。我还编写了一个通过AddPrinterDriver和AddPrinter函数安装打印机驱动程序的设置。
到目前为止,这么好。问题是,如果我想将这台打印机从x64系统共享到x86系统,x64打印服务器需要安装x86系统的附加驱动程序。
现在我可以通过“打印机属性”安装其他驱动程序 - > “分享” - > “其他驱动程序”并选择正确的.inf文件,但我想通过我的安装程序来完成。
有人知道如何做到这一点吗?
感谢您的帮助!
答案 0 :(得分:2)
所以我自己找到了解决方案。必须有一种更好,更简单的方法,但它有效。
安装驱动程序时,还要将正确的体系结构文件复制到其他体系结构。 x86驱动程序到x86后台驱动程序驱动程序目录,x64到x64后台驱动程序驱动程序目录等。
然后,在调用AddPrinterDriver和AddPrinter之前,必须为要支持的其他每个体系结构添加一些注册表值。然后仅为安装驱动程序的操作系统的基本体系结构调用AddPrinterDriver和AddPrinter。
必须将注册表值添加到
系统\ CurrentControlSet \控制\打印\环境\ {TARGET_ENVIROMENT} \驱动\版-3 \ {NAME_OF_YOUR_DRIVER}
{TARGET_ENVIROMENT}是您要支持的其他环境,例如“Windows NT x86”; “Windows x64”; “Windows IA64”和{NAME_OF_YOUR_DRIVER}必须与您用于AddPrinterDriver的动画名称相匹配。您必须添加的值是AddPrinterDriver将添加到您的系统环境中的值的副本。您可以在下面的代码示例中详细查看它们。之后,只需为系统架构调用AddPrinterDriver和AddPrinter,其他驱动程序也将出现。
在Win32中,您可以使用以下命令在x64系统上安装x86和x64的驱动程序(此示例不进行错误检查):
DWORD uSize;
BYTE driver_dir_x86[MAX_PATH];
BYTE driver_dir_x64[MAX_PATH];
GetPrinterDriverDirectory(NULL,"Windows NT x86",1,driver_dir_x86,MAX_PATH,&uSize);
GetPrinterDriverDirectory(NULL,"Windows x64",1,driver_dir_x64,MAX_PATH,&uSize);
CopyFile(".\x86\printer_driver.dll",driver_dir_x86);
CopyFile(".\x86\PRINTER.PPD",driver_dir_x86);
CopyFile(".\x86\PRINTERUI.DLL",driver_dir_x86);
CopyFile(".\x86\PRINTER.HLP",driver_dir_x86);
CopyFile(".\x64\printer_driver.dll",driver_dir_x64);
CopyFile(".\x86\PRINTER.PPD",driver_dir_x64);
CopyFile(".\x86\PRINTERUI.DLL",driver_dir_x64);
CopyFile(".\x86\PRINTER.HLP",driver_dir_x64);
//Insert x86 additional drivers to registry
RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Print\\Environments\\Windows NT x86\\Drivers\\Version-3\\", 0, KEY_ALL_ACCESS, &hkey);
RegCreateKey(hkey, "My_Printer_Drivername", &hsubkey); {
RegSetValueEx(hsubkey, "Dependent Files", 0, REG_MULTI_SZ, (BYTE*)"", lstrlen("")+1);
RegSetValueEx(hsubkey, "Previous Names", 0, REG_MULTI_SZ, (BYTE*)"", lstrlen("")+1);
RegSetValueEx(hsubkey, "ColorProfiles", 0, REG_MULTI_SZ, (BYTE*)"", lstrlen("")+1);
RegSetValueEx(hsubkey, "CoreDependencies", 0, REG_MULTI_SZ, (BYTE*)"", lstrlen("")+1);
DWORD Val = 3;
RegSetValueEx(hsubkey, "Version", 0, REG_DWORD, (BYTE*)&Val, sizeof(DWORD));
Val = 0;
RegSetValueEx(hsubkey, "TempDir", 0, REG_DWORD, (BYTE*)&Val, sizeof(DWORD));
Val = 2;
RegSetValueEx(hsubkey, "Attributes", 0, REG_DWORD, (BYTE*)&Val, sizeof(DWORD));
Val = 0;
RegSetValueEx(hsubkey, "PrinterDriverAttributes", 0, REG_DWORD, (BYTE*)&Val, sizeof(DWORD));
RegSetValueEx(hsubkey, "Configuration File", 0, REG_SZ, (BYTE*)"PRINTERUI.DLL", lstrlen("PRINTERUI.DLL")+1);
RegSetValueEx(hsubkey, "Data File", 0, REG_SZ, (BYTE*)"PRINTER.PPD", lstrlen("PRINTER.PPD")+1);
RegSetValueEx(hsubkey, "Driver", 0, REG_SZ, (BYTE*)"printer_driver.dll", lstrlen("printer_driver.dll")+1);
RegSetValueEx(hsubkey, "Help File", 0, REG_SZ, (BYTE*)"PRINTER.HLP", lstrlen("PRINTER.HLP")+1);
RegSetValueEx(hsubkey, "Monitor", 0, REG_SZ, (BYTE*)"", lstrlen("")+1);
RegSetValueEx(hsubkey, "Datatype", 0, REG_SZ, (BYTE*)"RAW", lstrlen("RAW")+1);
RegSetValueEx(hsubkey, "Manufacturer", 0, REG_SZ, (BYTE*)"", lstrlen("")+1);
RegSetValueEx(hsubkey, "OEM URL", 0, REG_SZ, (BYTE*)"", lstrlen("")+1);
RegSetValueEx(hsubkey, "HardwareID", 0, REG_SZ, (BYTE*)"", lstrlen("")+1);
RegSetValueEx(hsubkey, "Provider", 0, REG_SZ, (BYTE*)"", lstrlen("")+1);
RegSetValueEx(hsubkey, "Print Processor", 0, REG_SZ, (BYTE*)"", lstrlen("")+1);
RegSetValueEx(hsubkey, "VendorSetup", 0, REG_SZ, (BYTE*)"", lstrlen("")+1);
RegSetValueEx(hsubkey, "InfPath", 0, REG_SZ, (BYTE*)"", lstrlen("")+1);
RegSetValueEx(hsubkey, "DriverDate", 0, REG_SZ, (BYTE*)"01/01/2010", lstrlen("01/01/2010")+1);
RegSetValueEx(hsubkey, "DriverVersion", 0, REG_SZ, (BYTE*)"1.0.0.0", lstrlen("1.0.0.0")+1);
RegSetValueEx(hsubkey, "MinInboxDriverVerDate", 0, REG_SZ, (BYTE*)"01/01/2010", lstrlen("01/01/2010")+1);
RegSetValueEx(hsubkey, "MinInboxDriverVerVersion", 0, REG_SZ, (BYTE*)"1.0.0.0", lstrlen("1.0.0.0")+1);
RegCloseKey(hsubkey);
RegCloseKey(hkey);
//Add x64 printer driver
DRIVER_INFO_3 di3;
ZeroMemory(&di3, sizeof(DRIVER_INFO_3));
di3.cVersion = 0x03;
di3.pConfigFile = "PRINTERUI.DLL";
di3.pDataFile = "PRINTER.PPD";
di3.pDependentFiles = "";
di3.pDriverPath = "printer_driver.dll";
di3.pEnvironment = "Windows x64";
di3.pHelpFile = "PRINTER.HLP";
di3.pMonitorName = NULL;
di3.pName = "My_Printer_Drivername";
di3.pDefaultDataType = TEXT("RAW");
AddPrinterDriver(NULL, 3, (LPBYTE)&di3);