AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

about PrintDlgEx and other Printer APIs

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
hughman



Joined: 11 Feb 2007
Posts: 92

PostPosted: Fri Sep 18, 2009 5:39 am    Post subject: about PrintDlgEx and other Printer APIs Reply with quote

1.
I can Call PrintDlg to display the print dialog via the same method while PrintDlgEx can't. What's wrong about my funciton?

Code:

/*
typedef struct tagPDEX {
    DWORD lStructSize;
    HWND hwndOwner;
    HGLOBAL hDevMode;
    HGLOBAL hDevNames;
    HDC hDC;
    DWORD Flags;
    DWORD Flags2;
    DWORD ExclusionFlags;
    DWORD nPageRanges;
    DWORD nMaxPageRanges;
    LPPRINTPAGERANGE lpPageRanges;
    DWORD nMinPage;
    DWORD nMaxPage;
    DWORD nCopies;
    HINSTANCE hInstance;
    LPCTSTR lpPrintTemplateName;
    LPUNKNOWN lpCallback;
    DWORD nPropertyPages;
    HPROPSHEETPAGE *lphPropertyPages;
    DWORD nStartPage;
    DWORD dwResultAction;
} PRINTDLGEX, *LPPRINTDLGEX;
*/

Printer_LoadPrintDlgEx(hParent)
{
   VarSetCapacity(structPDX, SizeOf_structPDX := 84, 0)
   NumPut(SizeOf_structPDX, structPDX, 0)
   NumPut(hParent, structPDX, 4)   ; hwndOwner, diffrent from PrintDlg, it can't be null
   PD_NOPAGENUMS:=0x8   ; if the PD_NOPAGENUMS flag is not specified, lpPageRanges must be non-NULL.
   PD_RETURNDC:=0x100
   NumPut(PD_RETURNDC | PD_NOPAGENUMS, structPDX, 20)
   DllCall("comdlg32\PrintDlgExA", "UInt", &structPDX)
   hDC := NumGet(structPDX, 16)

   Return hDC
}


2.
Another problem is that when I should add "A" or "W" to the called funtion. It seems no need to do so for many other funtions, but GetDefaultPrinter, PrintDlg, PrintDlgEx, etc , can't work without the suffix.

3.
Code:

   nSize := VarSetCapacity(sPrinterName, 256)
   DllCall("winspool.drv\GetDefaultPrinterA", "Str", sPrinterName, "UIntP", nSize)
   VarSetCapacity(hPrinter, 4)
   DllCall("winspool.drv\OpenPrinterA", "Str", sPrinterName, "Int", hPrinter, "UInt", 0)
   MsgBox % hPrinter


hPrinter retrun null, what's the problem?[/code]
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 7159

PostPosted: Fri Sep 18, 2009 6:16 am    Post subject: Re: about PrintDlgEx and other Printer APIs Reply with quote

Quote:
2.
Another problem is that when I should add "A" or "W" to the called funtion. It seems no need to do so for many other funtions, but GetDefaultPrinter, PrintDlg, PrintDlgEx, etc , can't work without the suffix.


  • "A' stands for Ansi and "W" for Unicode ( Wide Character )
  • For DllCall(), the first parameter should be the exact exported function name ( case sensitive ), and if not, AHK would return an errorlevel of -4
    Quote:
    -4: The specified function could not be found inside the DLL.

    Note: I have seen Lexikos mentioning elsewhere that AHK automatically appends an "A" to function names, but I am unsure

  • To view the exported functions of a DLL, you may use Dependency Walker



Quote:
3.
hPrinter retrun null, what's the problem?


Code:
nSize := VarSetCapacity( sPrinterName,256 )
DllCall( "winspool.drv\GetDefaultPrinterA", Str,sPrinterName, UIntP,nSize )
DllCall( "winspool.drv\OpenPrinterA", Str,sPrinterName, IntP,hPrinter, UInt,0 )
MsgBox % sPrinterName "`n" hPrinter
Back to top
View user's profile Send private message
hughman



Joined: 11 Feb 2007
Posts: 92

PostPosted: Sat Sep 19, 2009 3:54 pm    Post subject: Reply with quote

thx ,SKAN, it's a good utility.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group