SetEnvironment

  int SetEnvironment(lpszPort, lpvEnviron, cbMaxCopy)    
  LPCSTR lpszPort; /* address of port name */
  const void FAR* lpvEnviron; /* address of buffer for new environment */
  UINT cbMaxCopy; /* maximum number of bytes to copy */

The SetEnvironment function copies the contents of the specified buffer into the environment associated with the device attached to the specified system port. The environment, maintained by GDI, contains binary data used by GDI whenever a device context is created for the device on the given port.

Parameters

lpszPort

Points to a null-terminated string that specifies the name of the port.

lpvEnviron

Points to the buffer that contains the new environment. This buffer is in the form of a DEVMODE structure. The DEVMODE structure has the following form:

typedef struct _devicemode { /* dm */

char dmDeviceName[CCHDEVICENAME];

WORD dmSpecVersion;

WORD dmDriverVersion;

WORD dmSize;

WORD dmDriverExtra;

DWORD dmFields;

short dmOrientation;

short dmPaperSize;

short dmPaperLength;

short dmPaperWidth;

short dmScale;

short dmCopies;

short dmDefaultSource;

short dmPrintQuality;

short dmColor;

short dmDuplex;

short dmYResolution;

short dmTTOption;

} DEVMODE;

cbMaxCopy

Specifies the maximum number of bytes to copy to the buffer.

Return Value

The return value is the number of bytes copied to the environment, if the function is successful. It is zero if there is an error or 1 if the environment is deleted.

Comments

The SetEnvironment function is used by device drivers.

The SetEnvironment function deletes any existing environment. If there is no environment for the given port, SetEnvironment creates one. If the cbMaxCopy parameter is zero, the existing environment is deleted and not replaced.

The first member of the DEVMODE structure pointed to by the lpvEnviron
parameter must be the same as that passed in the lpDestDevType parameter of
the Enable function. If lpszPort specifies a null port, the dmDeviceName member is used to locate the environment. The first member in the block pointed to by the lpEnviron parameter should be an atom that the printer driver has added to the global atom table.

See Also

GetEnvironment