CreateDC

This function creates a device context (DC) for a device.

HDC CreateDC( 
LPCTSTR lpszDriver, 
LPCTSTR lpszDevice, 
LPCTSTR lpszOutput, 
CONST DEVMODE *lpInitData
);

Parameters

  • lpszDriver
    [in] Long pointer to a null-terminated string that specifies the file name of a driver. If this parameter is set to NULL, the system returns a screen DC.

  • lpszDevice
    [in] Long pointer to a null-terminated string that specifies the name of the specific output device being used, as shown by the Print Manager (for example, "Epson FX-80"). It is not the printer model name. The lpszDevice parameter must be used.

    In Windows CE versions 2.0 and 2.01, this parameter is ignored.

  • lpszOutput
    [in] Long pointer to an output destination. It can be one of the following values, and the colon is required when specifying a port.

    Value Description
    COMx: Serial ports; x is a number from 1 to 9.
    LPTx: Parallel ports; x is a number from 1 to 9.
    IRDA: IRDA port. For Windows CE versions 2.0 and 2.01, use COM3: to specify the IRDA port.
    \\servername\sharename Universal naming convention (UNC) that identifies a network printer server.
  • lpInitData
    [in] Long pointer to a DEVMODE structure containing device-specific initialization data for the device driver. The lpInitData parameter must be NULL if the device driver is to use the default initialization (if any) specified by the user.

Return Values

The handle to a device context for the specified device indicates success. NULL indicates failure. To get extended error information, call GetLastError.

Remarks

Windows CE passes the lpInitData and lpszOutput parameters to the driver without modification. The lpszOutput parameter must contain a colon after the port—that is, use LPT1: or COM1:—otherwise, the connection fails.

When you no longer need the device context, call the DeleteDC function to delete it.

Requirements

Runs on Versions Defined in Include Link to
Windows CE OS 2.0 and later Wingdi.h   Mgdc.lib

Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

See Also

DeleteDC, GetLastError, DEVMODE

 Last updated on Tuesday, July 13, 2004

© 1992-2000 Microsoft Corporation. All rights reserved.