Microsoft KB Archive/80784

{|
 * width="100%"|

DOC: Suggested Changes to the DEVCAPS2 Sample App

 * }

Q80784

3.00 3.10 WINDOWS kbprg kbfile

-

The information in this article applies to:


 * Microsoft Windows Software Development Kit (SDK) 3.1

-

SUMMARY
DEVCAPS2 is a sample application developed for the Windows environment by Charles Petzold. DEVCAPS2 demonstrates how to retrieve various capabilities of a printer or display device. This sample is included in the book &quot;Programming Windows Version 3,&quot; published by Microsoft Press.

This article describes a change that should be made to the code in DEVCAPS2, and also to any application based on DEVCAPS2. This change works around a problem in calling the DeviceMode API.

Problem Description
When the user selects DeviceMode from the File menu and modifies the printer settings in the dialog box, the unmodified version of DEVCAPS2 does not update the WIN.INI file with the changed information. Similarly, any changes to printer settings made using the Control Panel are not reflected in the dialog box in DEVCAPS2.

The DeviceMode menu item is designed to allow the user to modify any printer settings globally, for all applications. Any application that uses the DeviceMode dialog box should use the new printer settings. In addition, the application should write the new printer settings into the WIN.INI file.

Resolution
Because the DEVCAPS2 program calls the DeviceMode API with incorrect parameters, it exhibits the behavior described above. The following code appears in the DEVCAPS2.C file starting at line 176:

  szOutput = strtok(szDriver,&quot;, &quot;); strcat(strcpy(szDriverFile, szDriver), &quot;.DRV&quot;); The code above sets szOutput equal to the name of the device driver (for example, &quot;EPSON9&quot;) rather than to the output port (for example, &quot;LPT1:&quot;). To correct this problem, modify the code to add an additional call to the strtok function, as in the following code:

  szOutput = strtok(szDriver, &quot;, &quot;); szOutput = strtok(NULL, &quot;, &quot;); strcat(strcpy(szDriverFile, szDriver), &quot;.DRV&quot;); After the modification, szOutput points to the output port. In the subsequent call to DeviceMode, the parameters are correct, and the function works as expected.

In Windows version 3.1, applications should call ExtDeviceMode instead of DeviceMode.

Additional query words: 3.00 3.10

Keywords : kbdocfix kbSDKWin16

Issue type :

Technology : kbAudDeveloper kbWin3xSearch kbSDKSearch kbWinSDKSearch kbWinSDK310