0

I am porting some Win32 code to Win64. The old code uses PrintDlg(), and runs fine on all versions of Windows (32 and 64 bit). The new code does not!

If I set up an all-zeroes PRINTDLG structure in my Win64 application, placing "120" in the lStructSize field, and call PrintDlg(), no dialog is shown, and the application crashes.

However, if I run the exact same image from within Visual Studio 2017 Pro, the dialog works as expected, every time!

Any thoughts about (a) why it works in VS, but crashes when run directly? And (b), what the heck I can do to fix it?!

Brian

biowizard
  • 61
  • 1

1 Answers1

0

While I am still unsure about why my code works in the VS2017 environment, but not in the stand-alone application, I have found the way to make my code work.

It's down to the stack pointer, RSP: on entry to my application (a Prolog compiler), I allocate my own, large, run-time changeable, private stack, and set RSP to its top.

If I call the PrintDlg() function with RSP in my private stack, it causes the GPF. If I reset it to the original Windows stack, then the function works as expected.

One extra line of code in my "WINAPI" macro - "MOV RSP,_OriginalRSP" - is all that's needed.

Thanks for your time, folks.

Brian

biowizard
  • 61
  • 1