It is a bit tricky and you have to carefully read the SDK. Here is the
source from my routine I am using. Actually there is some more error
handling and some Debug macros in the real version but I removed it here to
keep it to the point.
DWORD Level = 1;
char *pDirInfo = NULL;
DWORD cbBuf = 0;
DWORD pcbNeeded;
// Detect the right directory
GetPrinterDriverDirectory(NULL,NULL,Level,(LPBYTE) pDirInfo,0,&pcbNeeded);
pDirInfo = new char[1+pcbNeeded/sizeof(char)+50];
cbBuf = sizeof(char)*(1+pcbNeeded/sizeof(char)+50);
GetPrinterDriverDirectory(NULL,NULL,Level,(LPBYTE) pDirInfo,cbBuf,&pcbNeeded);
// I do not remember whether I really needed that. But I kept it in my
routine
if (pDirInfo[strlen(pDirInfo)-1]!='\\') {
pDirInfo=(char *)realloc(pDirInfo,strlen(pDirInfo)+1);
strcat(pDirInfo,"\\");
}
// DrvCopy is a small function that does the filecopy, from is "" so it is
the current directory. During the test I copied it from all the places it
was compiled to
CString from="";
CString to=pDirInfo;
DrvCopy("UNIDRV.DLL",from,to); //pDriverPath
DrvCopy("UNIDRVUI.DLL",from,to); //pConfigFile
DrvCopy("UNIDRV.HLP",from,to); //pHelpFile
DrvCopy("UNIRES.DLL",from,to); //pDependentFiles
DrvCopy(DRIVER_DLL,from,to); //pDependentFiles
DrvCopy("BMPCREATOR.GPD",from,to); //pConfigFile
DrvCopy("STDNAMES.GPD",from,to); //pDependentFiles
DrvCopy("BMPCREATOR.INI",from,to); //pDependentFiles
Level = 3;
DRIVER_INFO_3 DI3;
DI3.cVersion = 3;
DI3.pName = DxxDriver;
//DI3.pEnvironment = "Windows NT x86" ;
DI3.pEnvironment = NULL ;
DI3.pDriverPath = "\\UNIDRV.DLL";
DI3.pDataFile = "\\BMPCREATOR.GPD" ;
DI3.pConfigFile = "\\UNIDRVUI.DLL";
DI3.pHelpFile = "\\UNIDRV.HLP";
// DRIVER_DLL is defined to the name of my driver actually e.g.
"MYDRIVER.DLL"
DI3.pDependentFiles = "\\UNIRES.DLL\0\\" DRIVER_DLL
"\0\\BMPCREATOR.INI\0\\STDNAMES.GPD\0";
DI3.pMonitorName = NULL ;
DI3.pDefaultDataType = NULL ;
AddPrinterDriverEx(NULL,Level,(LPBYTE)&DI3,APD_COP Y_ALL_FILES);
Here is the add printer. I have some #defines in the beginning of my program
and also DxxPrinter is a char*
HANDLE aph;
DWORD Level = 2;
PRINTER_INFO_2 PI2;
CString CommentString;
PI2.pServerName=NULL;
PI2.pPrinterName=DxxPrinter;
PI2.pShareName=NULL;
PI2.pPortName=PORT_NAME;
PI2.pDriverName=DxxDriver;
if (InstLanguage=="de") {
PI2.pLocation=DESCRIPTION_DE;
CommentString=COMMENT_DE;
} else {
PI2.pLocation=DESCRIPTION_EN;
CommentString=COMMENT_EN;
}
PI2.pComment=CommentString.GetBuffer(0);
PI2.pDevMode=NULL;
PI2.pSepFile=NULL;
PI2.pPrintProcessor="WinPrint";
PI2.pDatatype="RAW";
PI2.pParameters=NULL;
PI2.pSecurityDescriptor=NULL;
//PI2.Attributes=PRINTER_ATTRIBUTE_DIRECT || PRINTER_ATTRIBUTE_RAW_ONLY ||
PRINTER_ATTRIBUTE_LOCAL;
PI2.Attributes=PRINTER_ATTRIBUTE_RAW_ONLY || PRINTER_ATTRIBUTE_LOCAL;
PI2.Priority=1;
PI2.DefaultPriority=1;
PI2.StartTime=0;
PI2.UntilTime=0;
PI2.Status=0;
PI2.cJobs=0;
PI2.AveragePPM=0;
aph=AddPrinter(NULL,Level,(LPBYTE)&PI2);
ClosePrinter(aph);
Regards,
Jürgen Hollfelder
www.hollfelder-edv.de
"Tobias Erichsen" <t.erichsen@gmx.de> schrieb im Newsbeitrag
news:d428eq$ham$1@news1.wobline.de...