Click to See Complete Forum and Search --> : API to install Printer on windows 98?
leojose
November 16th, 2005, 07:06 AM
Hi all,
In one of my earlier attempts, I was able to succesfully install and uninstall a Printer using the runndll32 printui.dll,PrintUIEntry method
http://www.codeguru.com/forum/showthread.php?t=353253&highlight=printer+install
But that method seems to work only on WindowsXP and not on Windows 98. Is there any available APIs or programmatical techniques I can use to install a printer on Win98?
Thanks
Marc G
November 16th, 2005, 07:32 AM
Why don't you use AddPrinter (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_1po2.asp)?
leojose
November 16th, 2005, 07:48 AM
Why don't you use AddPrinter (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_1po2.asp)?
Yes you are right, that hadn't come to my notice earlier.
But now I am confused over what to use...AddPrinter or AddPrinterDriver ? Can't figure out the difference between them :ehh:
Marc G
November 16th, 2005, 09:18 AM
Well, AddPrinter adds a printer while AddPrinterDriver adds a driver.
AddPrinter requires a printerdriver name. So I guess that if you want to install a new printer on your system, you first need to install the driver then create a printer that uses that driver.
leojose
November 16th, 2005, 12:03 PM
AddPrinter requires a printerdriver name. So I guess that if you want to install a new printer on your system, you first need to install the driver then create a printer that uses that driver.
I think I allready have a printer driver. I have a .inf and .ppd file
Now I try the following to install the printer...
HANDLE hPrinter;
PRINTER_INFO_2 printerinfo2;
DRIVER_INFO_3 driverinfo3;
DEVMODE devmode;
driverinfo3.cVersion=0;
driverinfo3.pName="Ghostscript";
driverinfo3.pEnvironment="Windows 98";
driverinfo3.pDriverPath="D:\\gsPrinter98\\ghostPDF.inf";
driverinfo3.pDataFile="D:\\gsPrinter98\\Gspdfw9x.ppd";
driverinfo3.pConfigFile="D:\\gsPrinter98\\ghostPDF.inf";
driverinfo3.pDependentFiles="D:\\gsPrinter98\\ghostPDF.ppd";
driverinfo3.pDefaultDataType="EMF";
if (!AddPrinterDriver(NULL,3,(LPBYTE)&driverinfo3))
{
cout << "AddPrinterDriver failed : " << GetLastError() << endl;
}
devmode.dmSize = sizeof(DEVMODE);
printerinfo2.pServerName = NULL;
printerinfo2.pPrinterName = "Ghostscript";
printerinfo2.pPortName = "FILE:";
printerinfo2.pDriverName = "Ghostscript";
printerinfo2.pDevMode = &devmode;
printerinfo2.Attributes = PRINTER_ATTRIBUTE_LOCAL;
printerinfo2.Status = PRINTER_STATUS_IO_ACTIVE|PRINTER_STATUS_WAITING;
if((hPrinter = AddPrinter(NULL,2,(LPBYTE)&printerinfo2))==NULL)
{
cout << "AddPrinter failed : " << GetLastError() << endl;
}
ClosePrinter(hPrinter);
but AddPrinter() returns an error value of 1797 (The printer driver is unknown)
I am not even sure of the values I am entering into the structures. Can I get a reference to any sample application that has used this API, it would be really helpful
PS: The AddPrinterDriver() function seemed to return without any errors.
Marc G
November 17th, 2005, 03:04 AM
Start by initializing your structures to all 0 values:
PRINTER_INFO_2 printerinfo2 = {0};
DRIVER_INFO_3 driverinfo3 = {0};
and see if that helps.
leojose
November 17th, 2005, 07:07 AM
I referred some source codes on the net and am having a feeling now that that AddPrinter can be used to install drivers of the type .drv. I am dealing with .inf type files and it must have a different approach altogether.
Code to install .drv type files
PRINTER_INFO_2 pi2;
DRIVER_INFO_2 di2;
HANDLE hPrinter;
ZeroMemory(&di2, sizeof(DRIVER_INFO_2));
di2.cVersion = 0;//1024;
di2.pName = "HP Laserjet 4Si"; // model name
di2.pEnvironment = "Windows 4.0";
di2.pDriverPath = "";//c:\\windows\\system\\hppcl5ms.drv";
di2.pDataFile = "";//c:\\windows\\system\\hppcl5ms.drv";
di2.pConfigFile = "";//c:\\windows\\system\\hppcl5ms.drv";
AddPrinterDriver(NULL, 2, (LPBYTE)&di2);
ZeroMemory(&pi2, sizeof(PRINTER_INFO_2));
pi2.pPrinterName = "HP Laserjet 4Si";//name to display (can be flexible)
pi2.pPortName = "FILE:";
pi2.pDriverName = "HP Laserjet 4Si";// same as model name
pi2.pPrintProcessor = "WinPrint";
pi2.pDatatype = "EMF";
if((hPrinter = AddPrinter(NULL, 2, (LPBYTE)&pi2))==NULL)
{
cout << "AddPrinter failed : " << GetLastError() << endl;
}
ClosePrinter(hPrinter);
I even tried something like this...
PUINT errorLine={0};
HINF hInf;
if (((hInf= SetupOpenInfFile("C:\\gsPrinter98\\ghostPDF.inf",
"Printer",INF_STYLE_WIN4,errorLine))==INVALID_HANDLE_VALUE))
{
cout << "SetupOpenInfFile failed : " << GetLastError() << endl;
}
if (!SetupInstallFromInfSection(NULL,hInf,NULL,SPINST_ALL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL))
{
cout << "SetupInstallFromInfSection failed : " << GetLastError() << endl;
}
but even that didn't help.
The rundll32 printui.dll is used to install inf type printers on winXP, but there is no such support for win98
If somebody knows a way to install .inf type files on win98, it will really be a big help
Thanks
Marc G
November 17th, 2005, 07:17 AM
I don't think I can help you any further :(
I have never used AddPrinter and AddPrinterDriver myself, I just pointed you in that direction.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.