Skip to main content

Cannot get results from GetSystemMetrics

  • December 2, 2011
  • 8 replies
  • 0 views

[Migrated content. Thread originally posted on 02 December 2011]

I am trying to get the screen dimensions using GetSystemMetrics from a remote PC. I am getting zeros. We are in the process of upgrading to 9.0 from 7.2. This was not an issue while using 7.2. The client machine that I am testing on is a Windows 7 64 bit machine. Below are the relevant sections of code. acuthin was actually crashing until I used the SIZE is phrase. This was not needed before...

EDIT: I used to also use the DLL_CONVENTION method before, and this does not work now either.
EDIT2: I have tested this on a Windows XP machine and the result is the same.

       01 SCREEN-INFO.
           03 SI-WIDTH         PIC  X(04) USAGE IS COMP-N.
           03 SI-HEIGHT        PIC  X(04) USAGE IS COMP-N.
           03 RTN-VAL          PIC  9(01).
           03 SM-CXSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 0.
           03 SM-CYSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 1.

       ....

       GET-SCREEN-RESOLUTION.
           INITIALIZE SI-WIDTH.
           INITIALIZE SI-HEIGHT.

           CALL "@[DISPLAY]:user32.dll@WINAPI"
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CXSCREEN
             SIZE IS
               4
             RETURNING
               SI-WIDTH
             ON EXCEPTION
               CONTINUE
           END-CALL.
     
           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CYSCREEN
             SIZE IS
               4
             RETURNING
               SI-HEIGHT
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CANCEL "@[DISPLAY]:User32.dll".
           .

8 replies

Stephen Hjerpe
  • Participating Frequently
  • 1100 replies
  • December 2, 2011

[Migrated content. Thread originally posted on 02 December 2011]

I am trying to get the screen dimensions using GetSystemMetrics from a remote PC. I am getting zeros. We are in the process of upgrading to 9.0 from 7.2. This was not an issue while using 7.2. The client machine that I am testing on is a Windows 7 64 bit machine. Below are the relevant sections of code. acuthin was actually crashing until I used the SIZE is phrase. This was not needed before...

EDIT: I used to also use the DLL_CONVENTION method before, and this does not work now either.
EDIT2: I have tested this on a Windows XP machine and the result is the same.

       01 SCREEN-INFO.
           03 SI-WIDTH         PIC  X(04) USAGE IS COMP-N.
           03 SI-HEIGHT        PIC  X(04) USAGE IS COMP-N.
           03 RTN-VAL          PIC  9(01).
           03 SM-CXSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 0.
           03 SM-CYSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 1.

       ....

       GET-SCREEN-RESOLUTION.
           INITIALIZE SI-WIDTH.
           INITIALIZE SI-HEIGHT.

           CALL "@[DISPLAY]:user32.dll@WINAPI"
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CXSCREEN
             SIZE IS
               4
             RETURNING
               SI-WIDTH
             ON EXCEPTION
               CONTINUE
           END-CALL.
     
           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CYSCREEN
             SIZE IS
               4
             RETURNING
               SI-HEIGHT
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CANCEL "@[DISPLAY]:User32.dll".
           .
Are you using the 32 bit runtime or 64 bit runtime on your Windows 7 machine. I suggest using the 32 bit runtime. Is the user32.dll getting found? On a 32 bit machine you'll have defaults to find user32.dll, whereas on the 64 bit machine, you may need to specify where to find user32.dll

  • Author
  • Rocketeer
  • 19312 replies
  • December 2, 2011

[Migrated content. Thread originally posted on 02 December 2011]

I am trying to get the screen dimensions using GetSystemMetrics from a remote PC. I am getting zeros. We are in the process of upgrading to 9.0 from 7.2. This was not an issue while using 7.2. The client machine that I am testing on is a Windows 7 64 bit machine. Below are the relevant sections of code. acuthin was actually crashing until I used the SIZE is phrase. This was not needed before...

EDIT: I used to also use the DLL_CONVENTION method before, and this does not work now either.
EDIT2: I have tested this on a Windows XP machine and the result is the same.

       01 SCREEN-INFO.
           03 SI-WIDTH         PIC  X(04) USAGE IS COMP-N.
           03 SI-HEIGHT        PIC  X(04) USAGE IS COMP-N.
           03 RTN-VAL          PIC  9(01).
           03 SM-CXSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 0.
           03 SM-CYSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 1.

       ....

       GET-SCREEN-RESOLUTION.
           INITIALIZE SI-WIDTH.
           INITIALIZE SI-HEIGHT.

           CALL "@[DISPLAY]:user32.dll@WINAPI"
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CXSCREEN
             SIZE IS
               4
             RETURNING
               SI-WIDTH
             ON EXCEPTION
               CONTINUE
           END-CALL.
     
           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CYSCREEN
             SIZE IS
               4
             RETURNING
               SI-HEIGHT
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CANCEL "@[DISPLAY]:User32.dll".
           .
Thanks for the response! This is a thin client application. The issue seems to be on the machine where the thin client is installed. User32.dll seems to be getting loaded.. I attached the Windows debugger to the acuthin.exe process, and right after the call to load the dll, I checked the loaded modules. User32.dll was indeed loaded. Everything else seems to work fine including calls to AcuBenchPrint.dll. For some reason, calling the function has been unsuccessful so far.

I will try to specify the location of user32.dll.

  • Author
  • Rocketeer
  • 19312 replies
  • December 2, 2011

[Migrated content. Thread originally posted on 02 December 2011]

I am trying to get the screen dimensions using GetSystemMetrics from a remote PC. I am getting zeros. We are in the process of upgrading to 9.0 from 7.2. This was not an issue while using 7.2. The client machine that I am testing on is a Windows 7 64 bit machine. Below are the relevant sections of code. acuthin was actually crashing until I used the SIZE is phrase. This was not needed before...

EDIT: I used to also use the DLL_CONVENTION method before, and this does not work now either.
EDIT2: I have tested this on a Windows XP machine and the result is the same.

       01 SCREEN-INFO.
           03 SI-WIDTH         PIC  X(04) USAGE IS COMP-N.
           03 SI-HEIGHT        PIC  X(04) USAGE IS COMP-N.
           03 RTN-VAL          PIC  9(01).
           03 SM-CXSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 0.
           03 SM-CYSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 1.

       ....

       GET-SCREEN-RESOLUTION.
           INITIALIZE SI-WIDTH.
           INITIALIZE SI-HEIGHT.

           CALL "@[DISPLAY]:user32.dll@WINAPI"
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CXSCREEN
             SIZE IS
               4
             RETURNING
               SI-WIDTH
             ON EXCEPTION
               CONTINUE
           END-CALL.
     
           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CYSCREEN
             SIZE IS
               4
             RETURNING
               SI-HEIGHT
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CANCEL "@[DISPLAY]:User32.dll".
           .
That is a no-go. Specifying the location of user32.dll had no effect. :-(

Stephen Hjerpe
  • Participating Frequently
  • 1100 replies
  • December 2, 2011

[Migrated content. Thread originally posted on 02 December 2011]

I am trying to get the screen dimensions using GetSystemMetrics from a remote PC. I am getting zeros. We are in the process of upgrading to 9.0 from 7.2. This was not an issue while using 7.2. The client machine that I am testing on is a Windows 7 64 bit machine. Below are the relevant sections of code. acuthin was actually crashing until I used the SIZE is phrase. This was not needed before...

EDIT: I used to also use the DLL_CONVENTION method before, and this does not work now either.
EDIT2: I have tested this on a Windows XP machine and the result is the same.

       01 SCREEN-INFO.
           03 SI-WIDTH         PIC  X(04) USAGE IS COMP-N.
           03 SI-HEIGHT        PIC  X(04) USAGE IS COMP-N.
           03 RTN-VAL          PIC  9(01).
           03 SM-CXSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 0.
           03 SM-CYSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 1.

       ....

       GET-SCREEN-RESOLUTION.
           INITIALIZE SI-WIDTH.
           INITIALIZE SI-HEIGHT.

           CALL "@[DISPLAY]:user32.dll@WINAPI"
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CXSCREEN
             SIZE IS
               4
             RETURNING
               SI-WIDTH
             ON EXCEPTION
               CONTINUE
           END-CALL.
     
           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CYSCREEN
             SIZE IS
               4
             RETURNING
               SI-HEIGHT
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CANCEL "@[DISPLAY]:User32.dll".
           .
Please contact Customer Care as this appears to be a bug.

  • Author
  • Rocketeer
  • 19312 replies
  • December 2, 2011

[Migrated content. Thread originally posted on 02 December 2011]

I am trying to get the screen dimensions using GetSystemMetrics from a remote PC. I am getting zeros. We are in the process of upgrading to 9.0 from 7.2. This was not an issue while using 7.2. The client machine that I am testing on is a Windows 7 64 bit machine. Below are the relevant sections of code. acuthin was actually crashing until I used the SIZE is phrase. This was not needed before...

EDIT: I used to also use the DLL_CONVENTION method before, and this does not work now either.
EDIT2: I have tested this on a Windows XP machine and the result is the same.

       01 SCREEN-INFO.
           03 SI-WIDTH         PIC  X(04) USAGE IS COMP-N.
           03 SI-HEIGHT        PIC  X(04) USAGE IS COMP-N.
           03 RTN-VAL          PIC  9(01).
           03 SM-CXSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 0.
           03 SM-CYSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 1.

       ....

       GET-SCREEN-RESOLUTION.
           INITIALIZE SI-WIDTH.
           INITIALIZE SI-HEIGHT.

           CALL "@[DISPLAY]:user32.dll@WINAPI"
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CXSCREEN
             SIZE IS
               4
             RETURNING
               SI-WIDTH
             ON EXCEPTION
               CONTINUE
           END-CALL.
     
           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CYSCREEN
             SIZE IS
               4
             RETURNING
               SI-HEIGHT
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CANCEL "@[DISPLAY]:User32.dll".
           .
Thank you. I am opening an incident now.

  • Author
  • Rocketeer
  • 19312 replies
  • December 5, 2011

[Migrated content. Thread originally posted on 02 December 2011]

I am trying to get the screen dimensions using GetSystemMetrics from a remote PC. I am getting zeros. We are in the process of upgrading to 9.0 from 7.2. This was not an issue while using 7.2. The client machine that I am testing on is a Windows 7 64 bit machine. Below are the relevant sections of code. acuthin was actually crashing until I used the SIZE is phrase. This was not needed before...

EDIT: I used to also use the DLL_CONVENTION method before, and this does not work now either.
EDIT2: I have tested this on a Windows XP machine and the result is the same.

       01 SCREEN-INFO.
           03 SI-WIDTH         PIC  X(04) USAGE IS COMP-N.
           03 SI-HEIGHT        PIC  X(04) USAGE IS COMP-N.
           03 RTN-VAL          PIC  9(01).
           03 SM-CXSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 0.
           03 SM-CYSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 1.

       ....

       GET-SCREEN-RESOLUTION.
           INITIALIZE SI-WIDTH.
           INITIALIZE SI-HEIGHT.

           CALL "@[DISPLAY]:user32.dll@WINAPI"
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CXSCREEN
             SIZE IS
               4
             RETURNING
               SI-WIDTH
             ON EXCEPTION
               CONTINUE
           END-CALL.
     
           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CYSCREEN
             SIZE IS
               4
             RETURNING
               SI-HEIGHT
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CANCEL "@[DISPLAY]:User32.dll".
           .
I was able to get this working (64-bit Windows 7 client running version 9.0 acuthin). But, I had the opposite result that you reported regarding the SIZE phrase: when I used it, acuthin crashed, but when I omitted it the program ran fine and I got the correct screen dimensions. I was also able to get correct results running directly on my Windows 7 PC via wrun32.exe (but omitting the @[DISPLAY] syntax). In both cases, I did not have to specify a path to user32.dll.

However... are you aware you can get this information without having to call the Windows API? The runtime already provides this info in the TERMINAL-INFO structure (if running remotely, it automatically retrieves it from the client).

This code will work equally well whether running directly on the desktop PC, or running remotely via Thin Client:

       WORKING-STORAGE SECTION.
           COPY "acucobol.def".


       PROCEDURE DIVISION.

      * The TERMINAL-ABILITIES structure is defined in acucobol.def
           ACCEPT TERMINAL-ABILITIES FROM TERMINAL-INFO.

           DISPLAY MESSAGE BOX
               "Physical Screen Width:  ", PHYSICAL-SCREEN-WIDTH,  X"0a"
               "Physical Screen Height: ", PHYSICAL-SCREEN-HEIGHT, X"0a"
               "Usable Screen Width:  ",   USABLE-SCREEN-WIDTH,    X"0a"
               "Usable Screen Height: ",   USABLE-SCREEN-HEIGHT,   X"0a"
               TITLE IS "Screen Dimensions".


The USABLE- values differ from the PHYSICAL- values by not including the space occupied by the Windows Task Bar (unless it's set to auto-hide).

In my testing, I got the exact same values in the PHYSICAL-SCREEN-WIDTH/HEIGHT as I got using the GetSystemMetrics call.

  • Author
  • Rocketeer
  • 19312 replies
  • December 6, 2011

[Migrated content. Thread originally posted on 02 December 2011]

I am trying to get the screen dimensions using GetSystemMetrics from a remote PC. I am getting zeros. We are in the process of upgrading to 9.0 from 7.2. This was not an issue while using 7.2. The client machine that I am testing on is a Windows 7 64 bit machine. Below are the relevant sections of code. acuthin was actually crashing until I used the SIZE is phrase. This was not needed before...

EDIT: I used to also use the DLL_CONVENTION method before, and this does not work now either.
EDIT2: I have tested this on a Windows XP machine and the result is the same.

       01 SCREEN-INFO.
           03 SI-WIDTH         PIC  X(04) USAGE IS COMP-N.
           03 SI-HEIGHT        PIC  X(04) USAGE IS COMP-N.
           03 RTN-VAL          PIC  9(01).
           03 SM-CXSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 0.
           03 SM-CYSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 1.

       ....

       GET-SCREEN-RESOLUTION.
           INITIALIZE SI-WIDTH.
           INITIALIZE SI-HEIGHT.

           CALL "@[DISPLAY]:user32.dll@WINAPI"
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CXSCREEN
             SIZE IS
               4
             RETURNING
               SI-WIDTH
             ON EXCEPTION
               CONTINUE
           END-CALL.
     
           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CYSCREEN
             SIZE IS
               4
             RETURNING
               SI-HEIGHT
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CANCEL "@[DISPLAY]:User32.dll".
           .
I really appreciate the help, Chuck. Using this option will indeed work. I am going to take the other suggested option presented in the incident that I filed, because I may need to call other DLLs, eventually.

I was compiling my project with the '-Cr' (RM/COBOL compatibility) option. The compiler options that I was using were ported over from our character-based screens which have been a round for a long time. We used to use RM/COBOL. I am removing that option and the SIZE IS clauses for this project as all the code that was written for this project was not RM/COBOL. I am sure that there are some real legacy programs in our character-based world that need this option still. I am not sure what caused this to show itself in the latest version of the compiler, but it is fixed.

I wanted to post what the final outcome was here. Thanks again! You guys are awesome!

  • Author
  • Rocketeer
  • 19312 replies
  • December 7, 2011

[Migrated content. Thread originally posted on 02 December 2011]

I am trying to get the screen dimensions using GetSystemMetrics from a remote PC. I am getting zeros. We are in the process of upgrading to 9.0 from 7.2. This was not an issue while using 7.2. The client machine that I am testing on is a Windows 7 64 bit machine. Below are the relevant sections of code. acuthin was actually crashing until I used the SIZE is phrase. This was not needed before...

EDIT: I used to also use the DLL_CONVENTION method before, and this does not work now either.
EDIT2: I have tested this on a Windows XP machine and the result is the same.

       01 SCREEN-INFO.
           03 SI-WIDTH         PIC  X(04) USAGE IS COMP-N.
           03 SI-HEIGHT        PIC  X(04) USAGE IS COMP-N.
           03 RTN-VAL          PIC  9(01).
           03 SM-CXSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 0.
           03 SM-CYSCREEN      PIC  X(04) USAGE IS COMP-N
              VALUE IS 1.

       ....

       GET-SCREEN-RESOLUTION.
           INITIALIZE SI-WIDTH.
           INITIALIZE SI-HEIGHT.

           CALL "@[DISPLAY]:user32.dll@WINAPI"
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CXSCREEN
             SIZE IS
               4
             RETURNING
               SI-WIDTH
             ON EXCEPTION
               CONTINUE
           END-CALL.
     
           CALL "@[DISPLAY]:GetSystemMetrics"
             USING BY VALUE
               SM-CYSCREEN
             SIZE IS
               4
             RETURNING
               SI-HEIGHT
             ON EXCEPTION
               CONTINUE
           END-CALL.

           CANCEL "@[DISPLAY]:User32.dll".
           .
Happy to help Bill. To summarize, the problem seemed to be triggered by the use of the -Cr compile option. When compiled with -Cr, without the SIZE IS clause on the CALL, a MAV (memory access violation) occurred. Adding the SIZE IS clause gets past the MAV but the return value from the CALL isn't populated (the value remains at zero or spaces, depending on how it was initialized). The resolution to making the CALL work was to remove the SIZE IS clause and not use the -Cr option.

One other point - you mentioned having to use the DLL_CONVENTION config variable in the past. The "@WINAPI" suffix on the name of the DLL is meant to accomplish the same thing (it actually overrides any setting of DLL_CONVENTION)... However, it's meant to be used on the function name, not the DLL name:

CALL "@[DISPLAY]:user32.dll" ...
CALL "@[DISPLAY]:GetSystemMetrics@WINAPI" ...

Changing this doesn't seem to affect the issues with the -Cr option, but good to know for future reference. This is explained in A Guide to Interoperating with ACUCOBOL-GT, Section 3.3.1.