home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / lpr32.zip / lpr32inst.c < prev    next >
C/C++ Source or Header  |  2001-06-14  |  5KB  |  193 lines

  1. #define  LINT_ARGS                     /* argument checking enabled          */
  2.  
  3. #define  INCL_DOS
  4. #define  INCL_GPI
  5. #undef   INCL_GPI
  6. #define  INCL_DEV
  7. #define  INCL_DOSMEMMGR                /* Include standard OS/2 support      */
  8. #define  INCL_DOSMODULEMGR             /* For DosLoadModule                  */
  9. #define  INCL_DOSPROCESS
  10. #define  INCL_GPILCIDS
  11. #define  INCL_WINCOMMON                /* Include Window Management support  */
  12. #define  INCL_WINDOWMGR
  13. #define  INCL_WINSWITCHLIST
  14. #define  INCL_WINPROGRAMLIST
  15. #define  INCL_WINMENUS
  16. #define  INCL_WINWINDOWMGR
  17. #define  INCL_WINMESSAGEMGR
  18. #define  INCL_WINDIALOGS
  19. #define  INCL_WINSTATICS
  20. #define  INCL_WINLISTBOXES
  21. #define  INCL_WINMENUS
  22. #define  INCL_WINSYS
  23. #define  INCL_WINFRAMEMGR
  24. #define  INCL_INCLWINACCELERATORS
  25. #define  INCL_WINPOINTERS
  26. #define  INCL_WINERRORS
  27. #define  INCL_WINSHELLDATA
  28.  
  29. #define  INCL_WINTYPES
  30. #define  INCL_WINACCELERATORS
  31. #define  INCL_WINBUTTONS
  32. #define  INCL_WINENTRYFIELDS
  33. #define  INCL_WINRECTANGLES
  34. #define  INCL_WINTIMER
  35. #define  INCL_WINSCROLLBARS
  36. #define  INCL_WINHEAP
  37. #define  INCL_SHLERRORS
  38. #define  INCL_WININPUT
  39. #define  INCL_WINHELP
  40. #define  INCL_WINSTDSPIN
  41.  
  42. #define  INCL_SPL
  43. #define  INCL_SPLP
  44. #define  INCL_SPLERRORS
  45. #define  INCL_SHLERRORS
  46. #define  INCL_DOSERRORS
  47. #define  INCL_WINHOOKS
  48.  
  49. int acrtused=1;                      /* Define variable to say this is a DLL */
  50.  
  51. #include    <os2.h>
  52.  
  53. #include    <stdlib.h>
  54. #include    <string.h>
  55. #include    <ctype.h>
  56. #include    <stdarg.h>
  57. #include    <stdio.h>
  58. #include    <stdlib.h>
  59. #include    <process.h>
  60. #include    "lpr32.h"
  61.  
  62. CHAR szDefaultPortDrvPath[] = { PATH_LPR32_PDR };
  63.  
  64. BOOL GetPortDescription ( HAB hab,
  65.                           HMODULE hModule,
  66.                           PSZ pszPortName,
  67.                           PSZ pszPortDesc )
  68. {
  69.    USHORT usID;
  70.    CHAR   chBuf[STR_LEN_PORTDESC];
  71.  
  72.    for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
  73.    {
  74.       WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chBuf);
  75.       if (!strcmp (pszPortName, chBuf))
  76.       {
  77.          strcpy (pszPortDesc, chBuf);
  78.          return(TRUE);
  79.       }
  80.    }
  81.    return(FALSE);
  82. }
  83. APIRET APIENTRY SplPdInstallPort ( HAB hab,PSZ pszPortName )
  84. {
  85.    CHAR    chBuf[STR_LEN_PORTNAME];
  86.    CHAR    chPortDesc[STR_LEN_PORTDESC];
  87.    ULONG   ulBootDrive;
  88.    HMODULE hModule;
  89.    CHAR    szPathName[260];    /* will contain full path to this port driver */
  90.  
  91.    if (!pszPortName)
  92.    {
  93.       return(ERROR_INVALID_PARAMETER);
  94.    }
  95.    strcpy(szDefaultPortDrvPath,PATH_LPR32_PDR);
  96.    DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
  97.                     sizeof (ULONG));
  98.    szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
  99.  
  100.    PrfWriteProfileString (HINI_SYSTEMPROFILE,
  101.                           "PM_PORT_DRIVER",
  102.                           "LPR32",
  103.                           szDefaultPortDrvPath);
  104.    hModule = 0L ;                             /* Init module handle to null */
  105.    DosLoadModule (NULL, 0, szPathName, &hModule);
  106.    if (!GetPortDescription (hab, hModule, pszPortName, chPortDesc))
  107.    {
  108.       strcpy( chPortDesc, pszPortName );
  109.    }
  110.    DosFreeModule (hModule);
  111.    strcpy (chBuf, APPNAME_LEAD_STR);
  112.    strcat (chBuf, pszPortName);
  113.    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  114.                                chBuf,
  115.                                KEY_DESCRIPTION,
  116.                                chPortDesc))
  117.    {
  118.       return (WinGetLastError (hab));
  119.    }
  120.  
  121.    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  122.                                chBuf,
  123.                                KEY_INITIALIZATION,
  124.                                DEF_INITIALIZATION))
  125.    {
  126.       return (WinGetLastError (hab));
  127.    }
  128.  
  129.    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  130.                                chBuf,
  131.                                KEY_TERMINATION,
  132.                                DEF_TERMINATION))
  133.    {
  134.       return (WinGetLastError (hab));
  135.    }
  136.  
  137.    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  138.                                chBuf,
  139.                                KEY_PORTDRIVER,
  140.                                DEF_PORTDRIVER))
  141.    {
  142.       return (WinGetLastError (hab));
  143.    }
  144.  
  145.    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  146.                                chBuf,
  147.                                KEY_TIMEOUT,
  148.                                DEF_TIMEOUT))
  149.    {
  150.       return (WinGetLastError (hab));
  151.    }
  152.    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  153.                                APPNAME_PM_SPOOLER_PORT,
  154.                                pszPortName,
  155.                                DEF_INITIALIZATION))
  156.    {
  157.       return (WinGetLastError (hab));
  158.    }
  159.    return(NO_ERROR);
  160. }
  161. int main(int argc,char **argv)
  162. {
  163.   APIRET rc;
  164.   HMQ                hmq;
  165.   HAB                 hab;
  166.   USHORT             i;
  167.   SHORT             j;
  168.   UCHAR              port[256];
  169.  
  170.   hab = WinInitialize(0);
  171.   hmq = WinCreateMsgQueue( hab , 0);
  172.  
  173.   if (argc != 2)
  174.     {
  175.        printf("Usage LPRINST x where x is a number 1..64\n\r");
  176.        exit(-1);
  177.     }
  178.   j = atoi(argv[1]);
  179.   if (j < 1 || j > 64)
  180.     {
  181.        printf("Invalid param must be 1..64\n\r");
  182.        exit(-1);
  183.     }
  184.   for(i=1;i<=j;i++)
  185.     {
  186.       sprintf(port,"LPR%d",i);
  187.       rc = SplPdInstallPort ( hab,port );
  188.     }
  189.   WinDestroyMsgQueue(hmq);
  190.   WinTerminate( hab );
  191.   return 0;
  192. }
  193.