Top
NetCOBOL V11.0 Getting Started
FUJITSU Software

A.32 Sample 31: Windows System Function Call

Sample 31 demonstrates how to invoke a Windows system function - for this example, a call to create a message box.

Overview

Sample 31 calls the Windows system function "MessageBoxA" to display a message in a message box with YES, NO and Cancel buttons. (Note that an "A" needs to be appended to the function call when the function call contains a character string parameter and you are working in ASCII, as opposed to Unicode data, when the suffix is "W".)

The call uses the STDCALL calling convention.

The message box returns a value indicating which button was pressed. This value is returned in the data item specified in the RETURNING phrase.

It is possible to refer to this return value in a batch file. In a batch file, you can access this return value by the name ERRORLEVEL. SAMPLE31.BAT demonstrates this as follows.

Files Included in Sample 31

COBOL Statements Used

Note

  1. Most Windows system functions (and C routines in general) require that strings be terminated with a null byte (X"00" or LOW-VALUE). The sample shows how you can place these bytes using reference modification.

  2. The Windows system function names are case sensitive. So be sure to get the case correct as in "MessageBoxA". You need to specify the compiler option "NOALPHAL" or "ALPHAL(WORD)" to ensure the COBOL system uses mixed case for the function name.

Building the Program

Project manager's build function is used to make the executable program.

  1. Start the Project Manager.

  2. Open project file SAMPLE31.PRJ.

    Library file "USER32.LIB" is required to link the program. It is used to ensure the linker can resolve the external reference "MessageBoxA". If you installed the product to something other than the default folder structure, you should change the folder name to match the folder structure you are using.

  3. Select "Build" from the project menu.

Executing the Program

  1. Open a Command Prompt, change directories to the SAMPLE31 folder, and execute SAMPLE31.BAT.

  2. The following message boxes are displayed. Click one of the buttons.

  3. The COBOL program detects which button was pressed and indicates such by displaying a message.

  4. When the [Cancel] button is clicked, the program is executed again.