Microsoft KB Archive/64900

Calling ExtDeviceMode with NULL Arguments

PSS ID Number: Q64900 Article last modified on 11-05-1993

3.00 MS-DOS

= SUMMARY =

Calling ExtDeviceMode [as well as DeviceCapabilities] with NULL arguments causes spurious results, usually crashing Windows. ExtDeviceMode and DeviceCapabilities are not functions that are a part of GDI, but rather are functions that are a part of the printer’s device driver. They must be linked dynamically at run time, using GetProcAddress to initialize a function pointer to the routine. This pointer variable is then used to execute the function. Because these functions are not an integral part of Windows, function prototypes have not been provided in WINDOWS.H. The lack of function prototypes may cause some difficulty in using these functions, specifically if the function arguments are not properly typecast. For example, simply specifying NULL as an argument to an LPSTR parameter may compile without error messages, but will produce unpredictable results at run time. There are two possible approaches to this PROBLEM ======= 1. Explicitly typecast all of the arguments to the function, as in the following example: /* Get length of driver’s DEVMODE structure / if (lpfnExtDeviceMode != NULL) iLength = (lpfnExtDeviceMode)( (HWND) hWnd, (HANDLE) hDriver, (DEVMODE FAR ) NULL, (LPSTR) szDeviceName, (LPSTR) szPort, (DEVMODE FAR ) NULL, (LPSTR) NULL, (WORD) 0 ); 2. Provide your own function prototype for the function pointer variable, as follows: int (lpfnExtDeviceMode) (HWND, HANDLE, DEVMODE FAR , LPSTR, LPSTR, DEVMODE FAR , LPSTR, WORD); … … / find the size of structure required / if (lpfnExtDeviceMode != NULL) in1 = (lpfnExtDeviceMode) (hwnd, hLibrary, NULL, (LPSTR)szDevice, (LPSTR)szOutput,NULL, NULL, 0); The arguments need not be explicitly typecast because they are done implicitly by the function prototype.

Additional reference words: 3.00 KBCategory: KBSubcategory: GdiPrnDrvfns Copyright Microsoft Corporation 1993.