Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Dllcall from 32 bit compile not working on 64 bit

$
0
0

Hi all,

 

Hope someone out there can help...

I'm having a problem trying to get the following test script to work under windows 8.1 64bit when compiled as 32 bit.

 

The 64bit compile works fine!?? Also, the 32 bit compile works fine on 32 bit...

 

I've found some information on the issue here

 

http://www.pinvoke.net/default.aspx/winspool/DocumentProperties.html

 

They refer to using 'IntPtr.Zero' which seems to be for C#.

 

More info here

 

https://msdn.microsoft.com/en-us/library/system.intptr.zero(v=vs.110).aspx

 

I'm sure the issue is with the data type set for the pointer to the devmode struct but I've tried everything I can think of.

 

Please see follow test script to show the issue.

 

Many thanks in advance

 

**Edit**  Cleaned up first line of _DocumentProperties() function, as per JohnOne's comment below.

AutoIt         
  1. #include <Array.au3>
  2. #include <WinAPIEx.au3>
  3.  
  4.  
  5. Global Const $DM_OUT_DEFAULT = 1
  6.  
  7. Local $sPrinterName = _GetDefaultPrinter()
  8. ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sPrinterName = ' & $sPrinterName & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
  9. Local $iDevModeSize = _DocumentProperties(0, $sPrinterName)
  10. ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iDevModeSize = ' & $iDevModeSize & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
  11. Local $ptrDevMode= _WinAPI_CreateBuffer($iDevModeSize);adding 100 due to
  12. Local $tDevMode = DllStructCreate($tagDEVMODE, $ptrDevMode)
  13. DllStructSetData($tDevMode, "Size", DllStructGetSize($tDevMode))
  14.  
  15. ;Local $iTestBufferSize = _WinAPI_GetMemorySize($ptrDevMode)
  16. ;MsgBox(4096, "Memory Size", $iTestBufferSize)
  17. ;_WinAPI_DisplayStruct($tDevMode, $tagDEVMODE)
  18.  
  19. _DocumentProperties(0, $sPrinterName, $tDevMode, $DM_OUT_DEFAULT)
  20.  
  21. _WinAPI_DisplayStruct($tDevMode, $tagDEVMODE)
  22.  
  23.  
  24. $tDevMode = 0
  25. _WinAPI_FreeMemory($ptrDevMode)
  26.  
  27.  
  28.  
  29. Func _DocumentProperties($hPrinter, $sPrinter, $tDevModeOutput = 0, $iFunc = 0)
  30.     Local $ptrDevModeInput = DllStructGetPtr($tDevModeOutput)
  31.     If $iFunc <> 0 Then MsgBox(0, "Pointer", $ptrDevModeInput)
  32.     Local $ptrDevModeOut = $ptrDevModeInput
  33.     Local $aResult = DllCall("Winspool.drv", "long", "DocumentPropertiesW", "hwnd", 0, "ptr", 0, "wstr", $sPrinter, "ptr", $ptrDevModeOut, "ptr", 0, "dword", $iFunc)
  34.     ;_ArrayDisplay($aResult)
  35.     Return $aResult[0]
  36.  
  37.  
  38.  
  39. Func _GetDefaultPrinter()
  40.     Local $tBufferSize = DllStructCreate("dword")
  41.     DllCall("Winspool.drv", "long", "GetDefaultPrinterW", "wstr", 0, "ptr", DllStructGetPtr($tBufferSize))
  42.     Local $tPrinterName = DllStructCreate("wchar[" & DllStructGetData($tBufferSize, 1) & "]")
  43.     DllCall("Winspool.drv", "long", "GetDefaultPrinterW", "ptr", DllStructGetPtr($tPrinterName), "ptr", DllStructGetPtr($tBufferSize))
  44.     Local $sPrinter = DllStructGetData($tPrinterName, 1)
  45.     $tPrinterName = 0
  46.     $tBufferSize = 0
  47.     Return $sPrinter

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>