Hello!
I have a problem with the code listed below. I want to add a Printer Driver
programatically. I am always receiving a message that the files cannot be
found. However the files are there. Even more then once. Has anybody ever
successfully used AddPrinterDriver or AddPrinterDriverEx???
Regards
Jürgen Hollfelder
Below my coding. I have also tried to give full path for dependent files. I
hape also tried with different versions and also used the whole driverpath.
I must admit I am new to C and rather be a Java and VB guy. However the same
in VB does not work either.
#include <windows.h>
void displayMessage();
void subAddPrinterDriver() {
BOOL ergeb;
DRIVER_INFO_3 DI3;
//Driverpath = "C:\WINDOWS\System32\spool\DRIVERS\W32X86\3"
DI3.cVersion = 1 ;
DI3.pEnvironment = “” ;
DI3.pName = “Mydrv” ;
DI3.pDataFile = “c:\drvfiles\HPDJ400.Gpd” ;
DI3.pDriverPath = “c:\drvfiles\UNIDRV.dll” ;
DI3.pConfigFile =“c:\drvfiles\UNIDRVUI.dll” ;
DI3.pHelpFile = “c:\drvfiles\UNIDRV.HLP” ;
DI3.pDependentFiles =“UNIRES.dll\0HPDRES.DLL\0STDNAMES.GPD\0\0” ;
DI3.pMonitorName = NULL ;
DI3.pDefaultDataType = “RAW” ;
ergeb = AddPrinterDriverEx(NULL, // server name
3, // driver information level
(LPBYTE)&DI3, // driver information buffer
APD_COPY_ALL_FILES
);
displayMessage();
}
void displayMessage() {
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
//MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
//MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(LPTSTR) &lpMsgBuf,
0,
NULL );
MessageBox( NULL, (LPCTSTR)lpMsgBuf, “Error”, MB_OK | MB_ICONINFORMATION );
//printf(lpMsgBuf);
LocalFree( lpMsgBuf );
}
//LONG WINAPI WndProc (HWND , UINT , UINT , LONG) ;
int WINAPI WinMain(HANDLE hInstance , HANDLE hPrevInstance , LPSTR
lpszCmdParam , int nCmdShow)
{
subAddPrinterDriver();
}</windows.h>