打印机驱动自动安装编程问题!!
1、这是安装的代码,参照一些例子,应该可以的,但安装失败!
2、DRIVER_INFO_2 Info2;这样定义的时候还可以看到下面有POS这个值HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-2 但DRIVER_INFO_3就没有了。
3、还要添加其他的函数实现吗?
void CInstallDlg::OnInstall()
{ DRIVER_INFO_3 Info2;
ZeroMemory(&Info2, sizeof(DRIVER_INFO_2));
Info2.cVersion = 3;
Info2.pName = "pos Printer";
Info2.pEnvironment = "Windows NT x86";
Info2.pDriverPath = "D:\\pos \\pos .DLL";
Info2.pDataFile = "D:\\pos \\BSD.DLL";
Info2.pConfigFile = "D:\\pos \\BSDUI.DLL";
Info2.pHelpFile = "D:\\pos \\pos .HLP";
Info2.pMonitorName = NULL;
Info2.pDefaultDataType = "RAW";
Info2.pDependentFiles = "pos .dll\0BSD.DLL\0BSDUI.DLL\0\0";
if (!AddPrinterDriver(NULL,3,(LPBYTE)&Info2))
{
DWORD error=GetLastError();
MessageBox("安装打印机驱动失败","安装错误",MB_ICONERROR|MB_OK);
}
//AddPrinter
PRINTER_INFO_2 xprinter;
ZeroMemory(&xprinter, sizeof(PRINTER_INFO_2));
xprinter.pDriverName="pos Printer";
xprinter.pPrinterName="pos Printer";
xprinter.pPortName="LPT1:";
xprinter.pPrintProcessor="WinPrint";
xprinter.pDatatype = "RAW";
xprinter.Attributes = PRINTER_ATTRIBUTE_LOCAL;
HANDLE prn=AddPrinter(NULL,2,(LPBYTE)&xprinter);
if (prn==NULL)
{
DWORD error=GetLastError();
MessageBox("安装打印机失败","安装错误",MB_ICONERROR|MB_OK);
}
else
{
//ConnectToPrinterDlg(NULL,0);
//PrinterProperties(NULL,prn);
ClosePrinter(prn);
MessageBox("安装打印机成功","AddPrinter",MB_OK);
}
}