How to use SHInvokePrinterCommand API?

I have used LoadLibrary and GetProcAddress as the MSDN suggest and those APIs work. Before calling SHInvokePrinterCommand I push all the parameters on stack. When calling SHInvokePrinterCommand the command succeeds as indicated by return value, but no Printer Properties dialog appears. I have tried to call that API with different parameters, but I get allways same result.

Source of my program is atteched.

Best regards, Sami
Posted on 2001-08-22 16:32:57 by SamiP
just an idea:
have you try to call GetDesktopWindow before pushing all the parameters on the stack for SHInvokePrinterCommand ?
Posted on 2001-08-22 18:00:03 by Bit7
angelo: Tested it now, and it doesn't work.

The thing I try to do is displaying Printer Properties dialog as it is shown when I rightclick my printer in the Printers dialog and select Properties.

Is there any other way to display that dialog than SHInvokePrinterCommand?

Posted on 2001-08-22 18:06:44 by SamiP

i've looked the help, to wirk they say that shell32.dll must be later than 4.71 version. Is the address that GetProcAddress return correct ??? Whats your version of the dll ?

not important, this work well and is easier:

.model flat,stdcall

extrn ExitProcess :proc
extrn GetDesktopWindow :proc
extrn OpenPrinterA :proc
extrn PrinterProperties :proc
extrn ClosePrinter :proc

szPrinterName db "Microsoft Fax", 0

Desktop dd ?
PrinterH dd ?

Start: call OpenPrinterA, offset szPrinterName, offset PrinterH

call PrinterProperties,\
0,\ ; // handle of parent window
PrinterH ; // handle of printer object

call ClosePrinter, PrinterH
call ExitProcess,0

end Start

Posted on 2001-08-22 19:09:58 by Bit7
Im using Windows 2000 so the shell32.dll version is 5.0.3315.2902.

Tried that other method you suggested, but it doesn't show complete properties! What I mean that I only get two tabs with that method instead of eight if I select Properties manually.
For example I can select paper sizes but there are no tab for ports.

Quite strange that it is so hard to display same properties that windows display when selecting Properties.

Posted on 2001-08-22 19:27:54 by SamiP
This is not a solution to SHInvokePrinterCommand problem, but I found that running following command:
rundll32 printui.dll,PrintUIEntry /p /n"HP DeskJet 850C"

gives me exactly what I was trying to get with SHInvokePrinterCommand. So at the moment I think this is the acceptaple solution.

If you know how to use that SHInvoke... API please let me know.

Posted on 2001-08-22 19:43:29 by SamiP
I didn't look at your code, but had no trouble getting the function
to work for me. hWin is the handle to the main window.

include \masm32\include\

includelib \masm32\lib\shell32.lib

lpBuf1 db "Xerox DocuPrint M750",0
lpBuf2 db " ",0

invoke SHInvokePrinterCommand,hWin,PRINTACTION_PROPERTIES,addr lpBuf1,addr lpBuf2,0
Posted on 2001-08-22 21:21:25 by anon
anon, could you send your code to me, so that I can test if it works on my computer too? My mail is

BTW I originally used GetDesktopWindow to get that window handle, but tried now with creating my own window and using that handle. I also tried using LoadLibrary GetProcAddress APIs and including and shell32.lib and directly invokin that function. But none of the methods seems to work :( I also used that lpBuf1 value is that what GetDefaultPrinter gives me. Also tried to write lpBuf1 what Control Panel/Printers shows my printer name is. Tried also chance my printer name, so it does not include any spaces. But no working results yet.

Posted on 2001-08-23 09:09:10 by SamiP
Check your mail :grin:
Posted on 2001-08-23 21:51:28 by anon