home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / i_o / getenv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  1.4 KB  |  53 lines

  1. /*
  2.  *
  3.  *  GetEnvironment
  4.  *  getenv.c
  5.  *  
  6.  *  This program demonstrates the use of the function GetEnvironment.
  7.  *  This function retrieves the currewnt environment that is associated with
  8.  *  the device attached to the system port specified by the first parameter,
  9.  *  and copies it into the buffer specified by the second parameter.
  10.  *
  11.  */
  12.  
  13. #include <windows.h>
  14. #include "getenv.h"
  15.  
  16. LPSTR far PASCAL lstrcpy( LPSTR, LPSTR );
  17.  
  18. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  19. HANDLE hInstance, hPrevInstance;
  20. LPSTR  lpszCmdLine;
  21. int    cmdShow;
  22. {
  23.   short nCopied;
  24.   short nSCopied;
  25.   DEVMODE devmode;
  26.  
  27.   lstrcpy(devmode.DeviceName, "HP LaserJet Series II");
  28.   devmode.orient = PORTRAIT;
  29.   devmode.cartridge = DEFAULT_CTG + CARTRIDGE;
  30.   devmode.paper = LETTER;
  31.  
  32.   nSCopied = SetEnvironment("LPT1:", (LPSTR)&devmode, sizeof(DEVMODE));
  33.   if (!nSCopied)
  34.      {
  35.      MessageBox (NULL, "Environment not set!", "SetEnvironment",
  36.         MB_OK|MB_ICONEXCLAMATION);
  37.      return (1);
  38.      }
  39.  
  40.   /* Clear out name string to show that we can retrieve it */
  41.   lstrcpy(devmode.DeviceName, "xxxxxxxxxxxxxx");
  42.  
  43.   MessageBox(NULL, "Getting environment", "GetEnvironment", MB_OK);
  44.   nCopied=GetEnvironment("LPT1:", (LPSTR)&devmode, sizeof(DEVMODE));
  45.  
  46.   if (nCopied)
  47.      MessageBox(NULL, devmode.DeviceName, "DeviceName", MB_OK);
  48.   else
  49.      MessageBox(NULL, "Environment not found", "GetEnvironment", MB_OK);
  50.  
  51.   return 0;
  52. }
  53.