http://bugs.winehq.org/show_bug.cgi?id=19400
--- Comment #11 from Nate Eldredge nate@thatsmathematics.com 2009-11-09 22:28:39 --- After some single stepping I found the problem. PSDRV_ExtDeviceMode is defined as CDECL but the application expects ExtDeviceMode to be STDCALL and pop its own arguments off the stack. The result, obviously, is that the stack pointer isn't where the application expects. What happens is not a crash exactly. The application has some sort of stack sentinel feature which I think is supposed to catch buffer overruns. But the sentinel is addressed relative to esp, so this check fails and it attempts to invoke the debugger.
I wasn't sure of exactly the right way to make the change, but I changed the definition of PSDRV_ExtDeviceMode to
INT WINAPI PSDRV_ExtDeviceMode
and I changed the corresponding line in wineps.drv.spec to
@ stdcall ExtDeviceMode(ptr long ptr ptr ptr ptr ptr long) PSDRV_ExtDeviceMode
The previous change to PSDRV_FindPrinterInfo that causes ExtDeviceMode to do something sensible when lspzDevice is NULL is also needed and still in effect.
After these changes, qwp runs without crashing, and printing works! So maybe someone who knows better than me can implement these changes in a good way and commit.
Another mystery regarding ExtDeviceMode: it is currently defined as
INT WINAPI PSDRV_ExtDeviceMode(LPSTR lpszDriver, HWND hwnd, LPDEVMODEA lpdmOutput, LPSTR lpszDevice, LPSTR lpszPort, LPDEVMODEA lpdmInput, LPSTR lpszProfile, DWORD dwMode)
Some MSDN links I found on Google suggest that the first two arguments should be reversed (google "extdevicemode"). However, qwp calls ExtDeviceMode with a first argument of 0 and a second argument of 0x7db40000, which seems more likely to be a hwnd than a string (it doesn't point to a meaningful looking string either). I wonder if there is some more authoritative documentation available, which might also confirm which calling convention is to be used. Perhaps if so, the other functions in wineps should be checked as well.
It might also be good if there is documentation that can be checked about the correct interface for