Skip to main content

MAV when run with 9.0.0 runtime, but not 8.1.2.1

  • March 21, 2011
  • 4 replies
  • 0 views

Christopher Ryan

[Migrated content. Thread originally posted on 21 March 2011]

We have a program that queries user32.dll to determine the computer's DPI settings, using the "GetDeviceCaps" function. The following code works fine when run with the 8.1.2.1 runtime, but gives a MAV when run with the version 9.0.0 runtime (compiled by the 8.1.2.1 compiler). The MAV occurs on the call to "ReleaseDC", and does not happen if you step over (skip) the line in the debugger, or if you comment that line out.

           SET ENVIRONMENT "DLL_CONVENTION" TO "1"
           CALL "USER32.DLL@WINAPI"
           CALL "GetDC" Using BY VALUE hwnd GIVING hdc
           CANCEL "user32.dll"
           CALL "gdi32.dll"
           CALL "GetDeviceCaps"
              USING BY VALUE hdc
              BY VALUE LOGPIXELSX
              GIVING DPIX
           END-CALL.
           CALL "GetDeviceCaps"
              USING BY VALUE hdc
              BY VALUE LOGPIXELSY
              GIVING DPIY
           END-CALL.
           CANCEL "gdi32.dll".
           CALL "USER32.DLL@WINAPI"
           CALL "ReleaseDC" Using BY VALUE hdc
           CANCEL "user32.dll"

4 replies

Stephen Hjerpe
  • Participating Frequently
  • March 21, 2011

[Migrated content. Thread originally posted on 21 March 2011]

We have a program that queries user32.dll to determine the computer's DPI settings, using the "GetDeviceCaps" function. The following code works fine when run with the 8.1.2.1 runtime, but gives a MAV when run with the version 9.0.0 runtime (compiled by the 8.1.2.1 compiler). The MAV occurs on the call to "ReleaseDC", and does not happen if you step over (skip) the line in the debugger, or if you comment that line out.

           SET ENVIRONMENT "DLL_CONVENTION" TO "1"
           CALL "USER32.DLL@WINAPI"
           CALL "GetDC" Using BY VALUE hwnd GIVING hdc
           CANCEL "user32.dll"
           CALL "gdi32.dll"
           CALL "GetDeviceCaps"
              USING BY VALUE hdc
              BY VALUE LOGPIXELSX
              GIVING DPIX
           END-CALL.
           CALL "GetDeviceCaps"
              USING BY VALUE hdc
              BY VALUE LOGPIXELSY
              GIVING DPIY
           END-CALL.
           CANCEL "gdi32.dll".
           CALL "USER32.DLL@WINAPI"
           CALL "ReleaseDC" Using BY VALUE hdc
           CANCEL "user32.dll"
I believe there is an issue with the 9.0 compiler and the @ symbol, please raise this issue with Customer Care so that it can be addressed.

Christopher Ryan
  • Author
  • Participating Frequently
  • March 21, 2011

[Migrated content. Thread originally posted on 21 March 2011]

We have a program that queries user32.dll to determine the computer's DPI settings, using the "GetDeviceCaps" function. The following code works fine when run with the 8.1.2.1 runtime, but gives a MAV when run with the version 9.0.0 runtime (compiled by the 8.1.2.1 compiler). The MAV occurs on the call to "ReleaseDC", and does not happen if you step over (skip) the line in the debugger, or if you comment that line out.

           SET ENVIRONMENT "DLL_CONVENTION" TO "1"
           CALL "USER32.DLL@WINAPI"
           CALL "GetDC" Using BY VALUE hwnd GIVING hdc
           CANCEL "user32.dll"
           CALL "gdi32.dll"
           CALL "GetDeviceCaps"
              USING BY VALUE hdc
              BY VALUE LOGPIXELSX
              GIVING DPIX
           END-CALL.
           CALL "GetDeviceCaps"
              USING BY VALUE hdc
              BY VALUE LOGPIXELSY
              GIVING DPIY
           END-CALL.
           CANCEL "gdi32.dll".
           CALL "USER32.DLL@WINAPI"
           CALL "ReleaseDC" Using BY VALUE hdc
           CANCEL "user32.dll"
GMCfourX4 originally wrote:
compiled by the 8.1.2.1 compiler


We have not compiled anything under version 9. This is just replacing the runtime and running our existing code (compiled under version 8) with the new runtime.

-Chris

[Migrated content. Thread originally posted on 21 March 2011]

We have a program that queries user32.dll to determine the computer's DPI settings, using the "GetDeviceCaps" function. The following code works fine when run with the 8.1.2.1 runtime, but gives a MAV when run with the version 9.0.0 runtime (compiled by the 8.1.2.1 compiler). The MAV occurs on the call to "ReleaseDC", and does not happen if you step over (skip) the line in the debugger, or if you comment that line out.

           SET ENVIRONMENT "DLL_CONVENTION" TO "1"
           CALL "USER32.DLL@WINAPI"
           CALL "GetDC" Using BY VALUE hwnd GIVING hdc
           CANCEL "user32.dll"
           CALL "gdi32.dll"
           CALL "GetDeviceCaps"
              USING BY VALUE hdc
              BY VALUE LOGPIXELSX
              GIVING DPIX
           END-CALL.
           CALL "GetDeviceCaps"
              USING BY VALUE hdc
              BY VALUE LOGPIXELSY
              GIVING DPIY
           END-CALL.
           CANCEL "gdi32.dll".
           CALL "USER32.DLL@WINAPI"
           CALL "ReleaseDC" Using BY VALUE hdc
           CANCEL "user32.dll"
Looks like you're missing a parameter to ReleaseDC, according to the MSDN description.

I ran your code and got the same results (MAV) using the 9.0 runtime (same result whether compiling with 8.1 or 9.0). And, like you, it worked fine with the 8.1 runtime.

One question is why it worked with 8.1 when it really shouldn't have.

But by adding the missing parameter, it works fine with 9.0 for me:

           CALL "ReleaseDC" Using
                   BY VALUE hwnd
                   BY VALUE hdc

           if return-code = 1          | ReleaseDC succeeded
              ...
           else                        | ReleaseDC failed
              ...
           end-if

Christopher Ryan
  • Author
  • Participating Frequently
  • March 22, 2011

[Migrated content. Thread originally posted on 21 March 2011]

We have a program that queries user32.dll to determine the computer's DPI settings, using the "GetDeviceCaps" function. The following code works fine when run with the 8.1.2.1 runtime, but gives a MAV when run with the version 9.0.0 runtime (compiled by the 8.1.2.1 compiler). The MAV occurs on the call to "ReleaseDC", and does not happen if you step over (skip) the line in the debugger, or if you comment that line out.

           SET ENVIRONMENT "DLL_CONVENTION" TO "1"
           CALL "USER32.DLL@WINAPI"
           CALL "GetDC" Using BY VALUE hwnd GIVING hdc
           CANCEL "user32.dll"
           CALL "gdi32.dll"
           CALL "GetDeviceCaps"
              USING BY VALUE hdc
              BY VALUE LOGPIXELSX
              GIVING DPIX
           END-CALL.
           CALL "GetDeviceCaps"
              USING BY VALUE hdc
              BY VALUE LOGPIXELSY
              GIVING DPIY
           END-CALL.
           CANCEL "gdi32.dll".
           CALL "USER32.DLL@WINAPI"
           CALL "ReleaseDC" Using BY VALUE hdc
           CANCEL "user32.dll"
Chuck,
Good catch. It does look like it should not have worked under version 8 either.

Thank you!
-Chris