Jump to content

..


Daddy
 Share

Recommended Posts

try this

Edit: not so excellent...

Replaced code with added string length check call to lstrlenW

as pointed out here by trancexx

I do know about not using magic numbers like 4096 as found in some of the UDFs,

but did not know what API or constant (like MAX_PATH etc) to use in this case.

some APIs are called without certain parameters so the required size to use for the call is returned.

you learn something new everyday.

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <Array.au3>

Global Const $DN_DEFAULTPRN = 0x1
Global Const $tagDEVNAMES = "Align 1;WORD wDriverOffset;WORD wDeviceOffset;WORD wOutputOffset;WORD wDefault"
Global Const $tagDEVMODE = "Align 1;wchar dmDeviceName[32];WORD dmSpecVersion;WORD dmDriverVersion;WORD dmSize;WORD dmDriverExtra;DWORD dmFields;WORD dmOrientation;WORD dmPaperSize;WORD dmPaperLength;WORD dmPaperWidth;WORD dmScale;WORD dmCopies;WORD dmDefaultSource;WORD dmPrintQuality;WORD dmColor;WORD dmDuplex;WORD dmYResolution;WORD dmTTOption;WORD dmCollate;wChar dmFormName[32];WORD dmUnusedPadding;WORD dmBitsPerPixel;Int dmPelsWidth;Int dmPelsHeight;Int dmDisplayFlags;Int dmDisplayFrequency;DWORD dmICMMethod;DWORD dmICMIntent;DWORD dmMediaType;DWORD dmDitherType;DWORD dmReserved1;DWORD dmReserved2;DWORD dmPanningWidth;DWORD dmPanningHeight"
Global Const $tagPRINTDLGEX = "align 1;DWORD lStructSize;hwnd hwndOwner;hwnd hDevMode;hwnd hDevNames;hwnd hDC;DWORD Flags;DWORD Flags2;DWORD ExclusionFlags;DWORD nPageRanges;DWORD nMaxPageRanges;ptr lpPageRanges;DWORD nMinPage;DWORD nMaxPage;DWORD nCopies;hwnd hInstance;ptr lpPrintTemplateName;ptr lpCallback;DWORD nPropertyPages;ptr lphPropertyPages;DWORD nStartPage;DWORD dwResultAction;"
Global Enum Step *2 $PD_SELECTION, $PD_PAGENUMS, $PD_NOSELECTION, $PD_NOPAGENUMS, $PD_COLLATE, $PD_PRINTTOFILE, $PD_PRINTSETUP, $PD_NOWARNING, $PD_RETURNDC, $PD_RETURNIC, $PD_RETURNDEFAULT, $PD_SHOWHELP, $PD_ENABLEPRINTHOOK, $PD_ENABLESETUPHOOK, $PD_ENABLEPRINTTEMPLATE, $PD_ENABLESETUPTEMPLATE, $PD_ENABLEPRINTTEMPLATEHANDLE, $PD_ENABLESETUPTEMPLATEHANDLE, $PD_USEDEVMODECOPIESANDCOLLATE, $PD_DISABLEPRINTTOFILE, $PD_HIDEPRINTTOFILE, $PD_NONETWORKBUTTON, $PD_CURRENTPAGE, $PD_NOCURRENTPAGE, $PD_EXCLUSIONFLAGS, $PD_ALLPAGES = 0, $PD_USELARGETEMPLATE = 268435456

Global $tPRINTDLGEX = _PrintDlgEx()
ConsoleWrite("! " & @error & " - " & @extended & @CRLF)

_DLLStructDisplay($tPRINTDLGEX, $tagPRINTDLGEX, "_GDI_PrintDlgEx")

Global $hMem_1 = DllStructGetData($tPRINTDLGEX, "hDevMode"), $pMem_1
If $hMem_1 Then $pMem_1 = _MemFunctions($hMem_1, 2)
If $pMem_1 Then
    Global $tDEVMODE = DllStructCreate($tagDEVMODE, $pMem_1)
    If @error Then
        _MemFunctions($hMem_1, 3)
        _MemFunctions($hMem_1, 1)
    EndIf
    _DLLStructDisplay($tDEVMODE, $tagDEVMODE, "DEVMODE")
EndIf

ConsoleWrite("!" & _MemFunctions(DllStructGetData($tPRINTDLGEX, "hDevNames"), 4) & @CRLF)

Global $hMem_2 = DllStructGetData($tPRINTDLGEX, "hDevNames"), $pMem_2
If $hMem_2 Then $pMem_2 = _MemFunctions($hMem_2, 2)
If $pMem_2 Then
    Global $tDEVNAMES = DllStructCreate($tagDEVNAMES, $pMem_2)
    If @error Then
        _MemFunctions($hMem_2, 3)
        _MemFunctions($hMem_2, 1)
    EndIf

    Global $tData, $aStrLen, $pDriver, $pDevice, $pOutput
    $pDriver = DllStructGetPtr($tDEVNAMES) + (DllStructGetData($tDEVNAMES, 1) * 2)
    $aStrLen = DllCall("kernel32.dll", "int", "lstrlenW", "ptr", $pDriver)
    If @error = 0 And $aStrLen[0] > 0 Then
        $tData = DllStructCreate("wchar[" & $aStrLen[0] & "]", $pDriver)
        ConsoleWrite('-Driver = ' & DllStructGetData($tData, 1) & @CRLF)
    EndIf

    $pDevice = DllStructGetPtr($tDEVNAMES) + (DllStructGetData($tDEVNAMES, 2) * 2)
    $aStrLen = DllCall("kernel32.dll", "int", "lstrlenW", "ptr", $pDevice)
    If @error = 0 And $aStrLen[0] > 0 Then
        $tData = DllStructCreate("wchar[" & $aStrLen[0] & "]", $pDevice)
        ConsoleWrite('-Device = ' & DllStructGetData($tData, 1) & @CRLF)
    EndIf

    $pOutput = DllStructGetPtr($tDEVNAMES) + (DllStructGetData($tDEVNAMES, 3) * 2)
    $aStrLen = DllCall("kernel32.dll", "int", "lstrlenW", "ptr", $pOutput)
    If @error = 0 And $aStrLen[0] > 0 Then
        $tData = DllStructCreate("wchar[" & $aStrLen[0] & "]", $pOutput)
        ConsoleWrite('-Output = ' & DllStructGetData($tData, 1) & @CRLF)
    EndIf

    ConsoleWrite('-DefaultPrn = ' & DllStructGetData($tDEVNAMES, 4) & @CRLF) ;$DN_DEFAULTPRN (0x1) if default printer used, otherwise 0

;~      Global $tData = DllStructCreate("wchar[256]", DllStructGetPtr($tDEVNAMES)+DllStructGetData($tDEVNAMES, 1)*2)
;~      ConsoleWrite('-DllStructGetData($tData, 1) = ' & DllStructGetData($tData, 1) & @crlf)
;~
;~      $tData = DllStructCreate("wchar[256]", DllStructGetPtr($tDEVNAMES)+DllStructGetData($tDEVNAMES, 2)*2)
;~      ConsoleWrite('-DllStructGetData($tData, 1) = ' & DllStructGetData($tData, 1) & @crlf)

;~      $tData = DllStructCreate("wchar[256]", DllStructGetPtr($tDEVNAMES)+DllStructGetData($tDEVNAMES, 3)*2)
;~      ConsoleWrite('-DllStructGetData($tData, 1) = ' & DllStructGetData($tData, 1) & @crlf)

    _DLLStructDisplay($tDEVNAMES, $tagDEVNAMES, "DEVNAMES")
EndIf

Func _PrintDlgEx($h_Wnd = 0)
    Local $t_PRINTDLGEX = DllStructCreate($tagPRINTDLGEX)
    If Not WinExists($h_Wnd) Then $h_Wnd = WinGetHandle(AutoItWinGetTitle())
    DllStructSetData($t_PRINTDLGEX, "lStructSize", DllStructGetSize($t_PRINTDLGEX))
    DllStructSetData($t_PRINTDLGEX, "hwndOwner", $h_Wnd)
    DllStructSetData($t_PRINTDLGEX, "Flags", BitOR($PD_ALLPAGES, $PD_NOPAGENUMS, $PD_USEDEVMODECOPIESANDCOLLATE, $PD_RETURNDC, $PD_NOSELECTION, $PD_NOCURRENTPAGE))
    DllStructSetData($t_PRINTDLGEX, "nCopies", 1)
    DllStructSetData($t_PRINTDLGEX, "nStartPage", 0xFFFFFFFF)
    Local $ret = DllCall("comdlg32.dll", "int", "PrintDlgExW", "ptr", DllStructGetPtr($t_PRINTDLGEX))
    If Not IsArray($ret) Or $ret[0] <> 0 Then Return SetError(@error, @extended, 0)
    Return $t_PRINTDLGEX
EndFunc   ;==>_PrintDlgEx

Func _MemFunctions($h_Mem, $i_Func)
    Local $a_Ret
    Switch $i_Func
        Case 1 ; Free
            $a_Ret = DllCall("kernel32.dll", "ptr", "GlobalFree", "handle", $h_Mem)
        Case 2 ; Lock
            $a_Ret = DllCall("kernel32.dll", "ptr", "GlobalLock", "handle", $h_Mem)
        Case 3 ; Unlock
            $a_Ret = DllCall("kernel32.dll", "bool", "GlobalUnlock", "handle", $h_Mem)
        Case 4 ; Size
            $a_Ret = DllCall("kernel32.dll", "ulong_ptr", "GlobalSize", "handle", $h_Mem)
    EndSwitch
    If @error Then Return SetError(@error, @extended, 0)
    Return $a_Ret[0]
EndFunc   ;==>_MemFunctions

Func _DLLStructDisplay(Const ByRef $stStruct, $sStString, $sStructName = "", $bBinConcat = False, $bStrConcat = True)
    ;Author: Ascend4nt
    ;from _DLLStructDisplay.au3
    If Not IsDllStruct($stStruct) Or Not IsString($sStString) Then Return SetError(1, -1, False)
    Local $iPos, $iSize, $iAlign, $iOffset, $iBaseAddress, $iSubItems, $iDispIndex
    Local $aTmp, $aSubItems, $aStDisplay, $aStDataTypes, $_iDLLSDArchIndepSz = 4
    If @AutoItX64 Then $_iDLLSDArchIndepSz = 8
    Local $_sDLLSDTypeSzXLat = "boolean,1ubyte,1char,1ushort,2word,2wchar,2udword,4uint,4ulong,4bool,4float,4double,8uint64,8uint_ptr," & $_iDLLSDArchIndepSz & "dword_ptr," & $_iDLLSDArchIndepSz & "ulong_ptr," & $_iDLLSDArchIndepSz & "hwnd," & $_iDLLSDArchIndepSz & "handle," & $_iDLLSDArchIndepSz & "lparam," & $_iDLLSDArchIndepSz & "wparam," & $_iDLLSDArchIndepSz & "lresult," & $_iDLLSDArchIndepSz
    If $sStructName <> "" Then $sStructName = ' (' & $sStructName & ')'
    If StringLeft($sStString, 5) = "align" Then
        $aTmp = StringRegExp($sStString, "(?i)align\h+(\d+)", 1)
        If @error Then Return SetError(1, 0, False)
        $sStString = StringTrimLeft($sStString, @extended)
        $iAlign = $aTmp[0]
    Else
        $iAlign = 8
    EndIf
    If StringRight($sStString, 1) = ';' Then $sStString = StringTrimRight($sStString, 1)
    $aStDataTypes = StringSplit($sStString, ';')
    $iBaseAddress = DllStructGetPtr($stStruct)
    $iSubItems = 0
    $aSubItems = StringRegExp($sStString, "\[(\d+)\]", 3)
    If Not @error Then
        For $i = 0 To UBound($aSubItems) - 1
            $iSubItems += $aSubItems[$i] - 1
        Next
    EndIf
    Dim $aStDisplay[$aStDataTypes[0] + 1 + $iSubItems][5]
    $aStDisplay[0][0] = "Index"
    $aStDisplay[0][1] = "DLL Struct Type + Description"
    $aStDisplay[0][2] = "Value"
    $aStDisplay[0][3] = "Offset [Base Ptr=" & $iBaseAddress & ", Alignment=" & $iAlign & ']'
    $aStDisplay[0][4] = "Size"
    $iDispIndex = 1
    For $i = 1 To $aStDataTypes[0]
        $aStDisplay[$iDispIndex][0] = $i
        $aStDataTypes[$i] = StringStripWS($aStDataTypes[$i], 7)
        $aStDisplay[$iDispIndex][1] = $aStDataTypes[$i]
        $aStDisplay[$iDispIndex][3] = Number(DllStructGetPtr($stStruct, $i) - $iBaseAddress)
        $iPos = StringInStr($aStDataTypes[$i], '[', 0)
        If $iPos Then
            $aSubItems = StringRegExp($aStDataTypes[$i], "\[(\d+)\]", 1)
            If @error Then Return SetError(1, $i, False)
            $iSubItems = $aSubItems[0]
            $aStDataTypes[$i] = StringLeft($aStDataTypes[$i], $iPos - 1)
        Else
            $iSubItems = 0
        EndIf
        $aTmp = StringRegExp($_sDLLSDTypeSzXLat, '(?i)' & StringRegExpReplace($aStDataTypes[$i], '\h.*', '') & ',(.)', 1)
        If @error Then Return SetError(1, $i, False)
        $iSize = $aTmp[0]
        $aStDisplay[$iDispIndex][4] = $iSize
        If $iSubItems And Not (StringInStr($aStDataTypes[$i], 'char', 0) And $bStrConcat) And Not (StringInStr($aStDataTypes[$i], 'byte', 0) And $bBinConcat) Then
            $aStDisplay[$iDispIndex][1] &= "  (sub item #1)"
            $aStDisplay[$iDispIndex][2] = String(DllStructGetData($stStruct, $i, 1))
            $iOffset = $aStDisplay[$iDispIndex][3]
            $iDispIndex += 1
            For $i2 = 2 To $iSubItems
                $iOffset += $iSize
                $aStDisplay[$iDispIndex][0] = ""
                $aStDisplay[$iDispIndex][1] = "______ (sub item #" & $i2 & ')'
                $aStDisplay[$iDispIndex][2] = String(DllStructGetData($stStruct, $i, $i2))
                $aStDisplay[$iDispIndex][3] = $iOffset
                $aStDisplay[$iDispIndex][4] = $iSize
                $iDispIndex += 1
            Next
        Else
            $aStDisplay[$iDispIndex][2] = String(DllStructGetData($stStruct, $i))
            If $iSubItems Then
                $aStDisplay[$iDispIndex][1] &= "  (concatenated)"
                $aStDisplay[$iDispIndex][4] &= ' (*' & $iSubItems & ')'
            EndIf
            $iDispIndex += 1
        EndIf
    Next
    ReDim $aStDisplay[$iDispIndex][5]
    _ArrayDisplay($aStDisplay, "DLL Struct" & $sStructName & " Contents [Base Ptr=" & $iBaseAddress & ", Alignment=" & $iAlign & ']')
    Return True
EndFunc   ;==>_DLLStructDisplay
Edited by rover

I see fascists...

Link to comment
Share on other sites

Daddy, in the future, pay attention to what others write in regards to their UDF's. Specifically, in this case, I'm talking about '_ That's a (slightly) modified version of my function in your code. The link is in my signature, and on the page you will see the agreement.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...