home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
lpr32.zip
/
lpr32inst.c
< prev
next >
Wrap
C/C++ Source or Header
|
2001-06-14
|
5KB
|
193 lines
#define LINT_ARGS /* argument checking enabled */
#define INCL_DOS
#define INCL_GPI
#undef INCL_GPI
#define INCL_DEV
#define INCL_DOSMEMMGR /* Include standard OS/2 support */
#define INCL_DOSMODULEMGR /* For DosLoadModule */
#define INCL_DOSPROCESS
#define INCL_GPILCIDS
#define INCL_WINCOMMON /* Include Window Management support */
#define INCL_WINDOWMGR
#define INCL_WINSWITCHLIST
#define INCL_WINPROGRAMLIST
#define INCL_WINMENUS
#define INCL_WINWINDOWMGR
#define INCL_WINMESSAGEMGR
#define INCL_WINDIALOGS
#define INCL_WINSTATICS
#define INCL_WINLISTBOXES
#define INCL_WINMENUS
#define INCL_WINSYS
#define INCL_WINFRAMEMGR
#define INCL_INCLWINACCELERATORS
#define INCL_WINPOINTERS
#define INCL_WINERRORS
#define INCL_WINSHELLDATA
#define INCL_WINTYPES
#define INCL_WINACCELERATORS
#define INCL_WINBUTTONS
#define INCL_WINENTRYFIELDS
#define INCL_WINRECTANGLES
#define INCL_WINTIMER
#define INCL_WINSCROLLBARS
#define INCL_WINHEAP
#define INCL_SHLERRORS
#define INCL_WININPUT
#define INCL_WINHELP
#define INCL_WINSTDSPIN
#define INCL_SPL
#define INCL_SPLP
#define INCL_SPLERRORS
#define INCL_SHLERRORS
#define INCL_DOSERRORS
#define INCL_WINHOOKS
int acrtused=1; /* Define variable to say this is a DLL */
#include <os2.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include "lpr32.h"
CHAR szDefaultPortDrvPath[] = { PATH_LPR32_PDR };
BOOL GetPortDescription ( HAB hab,
HMODULE hModule,
PSZ pszPortName,
PSZ pszPortDesc )
{
USHORT usID;
CHAR chBuf[STR_LEN_PORTDESC];
for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
{
WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chBuf);
if (!strcmp (pszPortName, chBuf))
{
strcpy (pszPortDesc, chBuf);
return(TRUE);
}
}
return(FALSE);
}
APIRET APIENTRY SplPdInstallPort ( HAB hab,PSZ pszPortName )
{
CHAR chBuf[STR_LEN_PORTNAME];
CHAR chPortDesc[STR_LEN_PORTDESC];
ULONG ulBootDrive;
HMODULE hModule;
CHAR szPathName[260]; /* will contain full path to this port driver */
if (!pszPortName)
{
return(ERROR_INVALID_PARAMETER);
}
strcpy(szDefaultPortDrvPath,PATH_LPR32_PDR);
DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
sizeof (ULONG));
szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
PrfWriteProfileString (HINI_SYSTEMPROFILE,
"PM_PORT_DRIVER",
"LPR32",
szDefaultPortDrvPath);
hModule = 0L ; /* Init module handle to null */
DosLoadModule (NULL, 0, szPathName, &hModule);
if (!GetPortDescription (hab, hModule, pszPortName, chPortDesc))
{
strcpy( chPortDesc, pszPortName );
}
DosFreeModule (hModule);
strcpy (chBuf, APPNAME_LEAD_STR);
strcat (chBuf, pszPortName);
if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
chBuf,
KEY_DESCRIPTION,
chPortDesc))
{
return (WinGetLastError (hab));
}
if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
chBuf,
KEY_INITIALIZATION,
DEF_INITIALIZATION))
{
return (WinGetLastError (hab));
}
if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
chBuf,
KEY_TERMINATION,
DEF_TERMINATION))
{
return (WinGetLastError (hab));
}
if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
chBuf,
KEY_PORTDRIVER,
DEF_PORTDRIVER))
{
return (WinGetLastError (hab));
}
if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
chBuf,
KEY_TIMEOUT,
DEF_TIMEOUT))
{
return (WinGetLastError (hab));
}
if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
APPNAME_PM_SPOOLER_PORT,
pszPortName,
DEF_INITIALIZATION))
{
return (WinGetLastError (hab));
}
return(NO_ERROR);
}
int main(int argc,char **argv)
{
APIRET rc;
HMQ hmq;
HAB hab;
USHORT i;
SHORT j;
UCHAR port[256];
hab = WinInitialize(0);
hmq = WinCreateMsgQueue( hab , 0);
if (argc != 2)
{
printf("Usage LPRINST x where x is a number 1..64\n\r");
exit(-1);
}
j = atoi(argv[1]);
if (j < 1 || j > 64)
{
printf("Invalid param must be 1..64\n\r");
exit(-1);
}
for(i=1;i<=j;i++)
{
sprintf(port,"LPR%d",i);
rc = SplPdInstallPort ( hab,port );
}
WinDestroyMsgQueue(hmq);
WinTerminate( hab );
return 0;
}