Jump to content
Sign in to follow this  
InunoTaishou

GDI+ Error description by code

Recommended Posts

InunoTaishou

Was getting some errors in my GDI+ project and wanted to know what they actually were, since I don't know what Error code 4 is.... So I looked it up on MSDN and put together a function that would give return a description of the error based on the code.

UDF:

; #FUNCTION# ====================================================================================================================
; Name...........:  _GDIPlus_GetErrorByCode
; Description....:  Get the error message for the @Extended error when a _GDIPlus_* function fails.
; Syntax.........:  _GDIPlus_GetErrorByCode ( [$iGDIError = @Extended [, Const $iReturnType = 0] ])
; Parameters.....:  $iGDIError   - The error to retrieve. Default is the last @Extended code.
;                   $iReturnType - What type the return should be. 0 will return a string, any other value returns an array.
;                                       - [0] Holds what type of error.
;                                       - [1] Holds the description.
; Return values..:  Success     - The error based on the code given in the formate requested.
;                   Failure     - The Error code given was out of range, not a valid code.
; Author.........:  InunoTaishou
; Remarks........:  Regardless of the error code a return in the format requested will be returned. If the code is out of range
;                   it will return an OutOfRange error.
; Related........:  GDIPlus
; Link...........:  https://msdn.microsoft.com/en-us/library/windows/desktop/ms534175%28v=vs.85%29.aspx
; Example........:  Yes
; ===============================================================================================================================
Func _GDIPlus_GetErrorByCode($iGDIError = @extended, Const $iReturnType = 0)
    Local Static $aErrors[22][2] = [["OK", "Indicates that the method call was successful."], _
            ["GenericError", "Indicates that there was an error on the method call, which is identified as something other than those defined by the other elements of this enumeration."], _
            ["InvalidParameter", "Indicates that one of the arguments passed to the method was not valid."], _
            ["OutOfMemory", "Indicates that the operating system is out of memory and could not allocate memory to process the method call. For an explanation of how constructors use the OutOfMemory status, see the Remarks section at the end of this topic."], _
            ["ObjectBusy", "Indicates that one of the arguments specified in the API call is already in use in another thread."], _
            ["InsufficientBuffer", "Indicates that a buffer specified as an argument in the API call is not large enough to hold the data to be received."], _
            ["NotImplemented", "Indicates that the method is not implemented."], _
            ["Win32Error", "Indicates that the method generated a Win32 error."], _
            ["WrongState", "Indicates that the object is in an invalid state to satisfy the API call. For example, calling Pen::GetColor from a pen that is not a single, solid color results in a WrongState status."], _
            ["Aborted", "Indicates that the method was aborted."], _
            ["FileNotFound", "Indicates that the specified image file or metafile cannot be found."], _
            ["ValueOverflow", "Indicates that the method performed an arithmetic operation that produced a numeric overflow."], _
            ["AccessDenied", "Indicates that a write operation is not allowed on the specified file."], _
            ["UnknownImageFormat", "Indicates that the specified image file format is not known."], _
            ["FontFamilyNotFound", "Indicates that the specified font family cannot be found. Either the font family name is incorrect or the font family is not installed."], _
            ["FontStyleNotFound", "Indicates that the specified style is not available for the specified font family."], _
            ["NotTrueTypeFont", "Indicates that the font retrieved from an HDC or LOGFONT is not a TrueType font and cannot be used with GDI+."], _
            ["UnsupportedGdiplusVersion", "Indicates that the version of GDI+ that is installed on the system is incompatible with the version with which the application was compiled."], _
            ["GdiplusNotInitialized", "Indicates that the GDI+API is not in an initialized state. To function, all GDI+ objects require that GDI+ be in an initialized state. Initialize GDI+ by calling GdiplusStartup."], _
            ["PropertyNotFound", "Indicates that the specified property does not exist in the image."], _
            ["PropertyNotSupported", "Indicates that the specified property is not supported by the format of the image and, therefore, cannot be set."], _
            ["ProfileNotFound", "Indicates that the color profile required to save an image in CMYK format was not found."]]
    Return (($iGDIError <= 21 And $iGDIError >= 0) ? _
            ($iReturnType = 0 ? $aErrors[$iGDIError][0] & ": " & $aErrors[$iGDIError][1] : StringSplit($aErrors[$iGDIError][0] & "|" & $aErrors[$iGDIError][1], "|", 2)) : _
            ($iReturnType = 0 ? SetError(10, 0, "OutOfRange: Error code " & $iGDIError & " is out of range") : SetError(10, $iGDIError, StringSplit("OutOfRange" & "|" & "Error code " & $iGDIError & " is out of range", "|", 2))))
EndFunc   ;==>_GDIPlus_GetErrorByCode

Example:

#include <Array.au3>
#include <GDIPlus.au3>
#include <GUIEdit.au3>

_GDIPlus_Startup()
Global Const $GUI_EVENT_CLOSE = -3
Global $hGui = GUICreate("GDI+ Error by code", 800, 500)
Global $hEdit = _GUICtrlEdit_Create($hGui, "", 10, 300, 780, 190)
Global $hPic = GUICtrlGetHandle(GUICtrlCreatePic("", 0, 0, 800, 290))
Global $hDc = _WinAPI_GetWindowDC($hPic)
Global $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDc)
Global $hPen = _GDIPlus_PenCreate(0xFF00FFFF, 6)
Global $hFormat = _GDIPlus_StringFormatCreate()
Global $hFontFamily = _GDIPlus_FontFamilyCreate("Segoe UI")
Global $hFont = _GDIPlus_FontCreate($hFontFamily, 24)
Global $tLaytout = _GDIPlus_RectFCreate(0, 0, 800, 290)
Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
Global $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Image1.jpg")
Global $hFile = FileOpen(@ScriptDir & "\Image2.jpg", 16 + 1)

_GDIPlus_StringFormatSetAlign($hFormat, 1)
_GDIPlus_StringFormatSetLineAlign($hFormat, 1)

GUISetState(@SW_SHOW, $hGui)

Debug("Error generating calls" & @CRLF)
Debug("Fake Font Family for _GDIPlus_FontFamilyCreate:" & _GDIPlus_FontFamilyCreate("AutoIt Rulez") & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)
Debug("Wrong Parameter for _GDIPlus_GraphicsClear: " & _GDIPlus_GraphicsClear(0, 0xFFF0F0F0) & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)
Debug("Load image for a file that's already open _GDIPlus_ImageLoadFromFile: " & _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Image2.jpg") & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)
Debug("Save image over a file that's already open _GDIPlus_ImageSaveToFile: " & _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Image2.jpg") & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)
_GDIPlus_ImageDispose($hImage)
Debug("Dispose image that's already been disposed _GDIPlus_ImageDispose: " & _GDIPlus_ImageDispose($hImage) & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)

Debug(@CRLF & "Non error generating calls" & @CRLF)
Debug("_GDIPlus_GraphicsClear: " & _GDIPlus_GraphicsClear($hGraphics, 0xFFF0F0F0) & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)
Debug("_GDIPlus_GraphicsDrawStringEx: " & _
      _GDIPlus_GraphicsDrawStringEx($hGraphics, "This is a GDI+ UDF for getting the error message by @Extended code." & @CRLF & "Author: InunoTaishou", $hFont, $tLaytout, $hFormat, $hBrush) & _
      @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF)
Debug("_GDIPlus_GraphicsDrawRect: " & _GDIPlus_GraphicsDrawRect($hGraphics, 2, 2, 796, 286, $hPen) & @CRLF & @TAB & _GDIPlus_GetErrorByCode() & @CRLF & @CRLF)

Debug("All available errors:" & @CRLF & @TAB)
For $i = 0 to 21
    Debug($i & ": " & _GDIPlus_GetErrorByCode($i) & @CRLF & @TAB)
Next
_ArrayDisplay(_GDIPlus_GetErrorByCode(22, 1), "Error 22")

Do

Until (GUIGetMsg() = $GUI_EVENT_CLOSE)

_WinAPI_ReleaseDC($hPic, $hDc)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_PenDispose($hPen)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_FontFamilyDispose($hFontFamily)
_GDIPlus_BrushDispose($hBrush)
FileClose($hFile)
GUIDelete($hGui)
Exit 0

Func Debug(Const $sMsg = "")
    _GUICtrlEdit_AppendText($hEdit, $sMsg)
EndFunc   ;==>Debug

; #FUNCTION# ====================================================================================================================
; Name...........:  _GDIPlus_GetErrorByCode
; Description....:  Get the error message for the @Extended error when a _GDIPlus_* function fails.
; Syntax.........:  _GDIPlus_GetErrorByCode ( [$iGDIError = @Extended [, Const $iReturnType = 0] ])
; Parameters.....:  $iGDIError   - The error to retrieve. Default is the last @Extended code.
;                   $iReturnType - What type the return should be. 0 will return a string, any other value returns an array.
;                                       - [0] Holds what type of error.
;                                       - [1] Holds the description.
; Return values..:  Success     - The error based on the code given in the formate requested.
;                   Failure     - The Error code given was out of range, not a valid code.
; Author.........:  InunoTaishou
; Remarks........:  Regardless of the error code a return in the format requested will be returned. If the code is out of range
;                   it will return an OutOfRange error.
; Related........:  GDIPlus
; Link...........:  https://msdn.microsoft.com/en-us/library/windows/desktop/ms534175%28v=vs.85%29.aspx
; Example........:  Yes
; ===============================================================================================================================
Func _GDIPlus_GetErrorByCode($iGDIError = @extended, Const $iReturnType = 0)
    Local Static $aErrors[22][2] = [["OK", "Indicates that the method call was successful."], _
            ["GenericError", "Indicates that there was an error on the method call, which is identified as something other than those defined by the other elements of this enumeration."], _
            ["InvalidParameter", "Indicates that one of the arguments passed to the method was not valid."], _
            ["OutOfMemory", "Indicates that the operating system is out of memory and could not allocate memory to process the method call. For an explanation of how constructors use the OutOfMemory status, see the Remarks section at the end of this topic."], _
            ["ObjectBusy", "Indicates that one of the arguments specified in the API call is already in use in another thread."], _
            ["InsufficientBuffer", "Indicates that a buffer specified as an argument in the API call is not large enough to hold the data to be received."], _
            ["NotImplemented", "Indicates that the method is not implemented."], _
            ["Win32Error", "Indicates that the method generated a Win32 error."], _
            ["WrongState", "Indicates that the object is in an invalid state to satisfy the API call. For example, calling Pen::GetColor from a pen that is not a single, solid color results in a WrongState status."], _
            ["Aborted", "Indicates that the method was aborted."], _
            ["FileNotFound", "Indicates that the specified image file or metafile cannot be found."], _
            ["ValueOverflow", "Indicates that the method performed an arithmetic operation that produced a numeric overflow."], _
            ["AccessDenied", "Indicates that a write operation is not allowed on the specified file."], _
            ["UnknownImageFormat", "Indicates that the specified image file format is not known."], _
            ["FontFamilyNotFound", "Indicates that the specified font family cannot be found. Either the font family name is incorrect or the font family is not installed."], _
            ["FontStyleNotFound", "Indicates that the specified style is not available for the specified font family."], _
            ["NotTrueTypeFont", "Indicates that the font retrieved from an HDC or LOGFONT is not a TrueType font and cannot be used with GDI+."], _
            ["UnsupportedGdiplusVersion", "Indicates that the version of GDI+ that is installed on the system is incompatible with the version with which the application was compiled."], _
            ["GdiplusNotInitialized", "Indicates that the GDI+API is not in an initialized state. To function, all GDI+ objects require that GDI+ be in an initialized state. Initialize GDI+ by calling GdiplusStartup."], _
            ["PropertyNotFound", "Indicates that the specified property does not exist in the image."], _
            ["PropertyNotSupported", "Indicates that the specified property is not supported by the format of the image and, therefore, cannot be set."], _
            ["ProfileNotFound", "Indicates that the color profile required to save an image in CMYK format was not found."]]
    Return (($iGDIError <= 21 And $iGDIError >= 0) ? _
            ($iReturnType = 0 ? $aErrors[$iGDIError][0] & ": " & $aErrors[$iGDIError][1] : StringSplit($aErrors[$iGDIError][0] & "|" & $aErrors[$iGDIError][1], "|", 2)) : _
            ($iReturnType = 0 ? SetError(10, 0, "OutOfRange: Error code " & $iGDIError & " is out of range") : SetError(10, $iGDIError, StringSplit("OutOfRange" & "|" & "Error code " & $iGDIError & " is out of range", "|", 2))))
EndFunc   ;==>_GDIPlus_GetErrorByCode

 

Image1.jpg

Image2.jpg

Edited by InunoTaishou
Forgot to include the Images I used in the example.

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • xiantez
      By xiantez
      This script used to work on an older version of AutoIT. Currently I am running AutoIT v3.3.14.5 and it's failing.
      Func PublicIP() ;Post public facing IP address Local $url = 'https://www.google.com/search?client=opera&q=what+is+my+ip&sourceid=opera&ie=UTF-8&oe=UTF-8' Local $getIPaddress = BinaryToString(InetRead($url)) Local $sStart = 'clamp:2">' Local $sEnd = '</div>' Local $ipaddress = _StringBetween($getIPaddress, $sStart, $sEnd For $i In $ipaddress MsgBox(0, 'External IP', "Your public IP address is " & $i) Next EndFunc ;==>PublicIP The console output shows:
      "C:\Users\user\Documents\AutoIT\Scripts\WSI Tools.au3" (197) : ==> Variable must be of type "Object".: For $i In $ipaddress For $i In $ipaddress^ ERROR ->14:12:16 AutoIt3.exe ended.rc:1 +>14:12:16 AutoIt3Wrapper Finished. >Exit code: 1 Time: 9.811
    • UEZ
      By UEZ
      AutoIt Windows Screenshooter
      Key Features:
      takes easily a screenshot from any visible window capture any region of the desktop incl. freehand capturing capture GUI controls and GUI menus separately capture a marked area every x seconds for a duration of y seconds create a GIF animation from saved frames (Vista or higher os required) capture to AVI file (without audio!) takes a screenshot from web sites (available only on Win7+ os and when Aero is enabled) put images to clipboard to paste to other applications easily color picker save image in different formats and also to PDF! add timestamp to saved images simple image editing options: greyscale, b&w, invert, rotate +-90° send image to printer and default email client preview of captured screens incl. zoom option multi monitor support display pixel color under mouse ruler basic image editor (paint, highlight, ellipse, rectangle, text and some graphic FX) watermark captured image no 3rd party tools or DLLs used - pure AutoIt! fully portable - no installation is needed multi language feature (Eng, Ger, Tur, Fra and Rus only) To do:
      capture content of scrollable window/control capture cascaded menus Due to DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "handle", $hMemDC, "int", 0) limitation some windows cannot be captured properly (GDI+, ProgDVB, etc.) but can take screenshots of hidden windows. One workaround is to use full screen capturing (F11/F12) or "Grab Screen" function! Or try double click with rmb on listview items (beta).
      Download source code (6295 downloads previously):  AutoIt Windows Screenshooter v1.81 Build 2018-08-12.7z (version 3.3.12.0+ needed!)
      You are not allowed to sell this code or just parts of it in a commercial project or modify it and distribute it with a different name!
      Download compiled Exe only: 4shared / Media Fire / Softpedia (1.54mb)
      Distributing copies of the program in compiled format (exe) must be free of any fee!
      -----> click here to Donate!  
       
      (Current donators: 1. Cuong N.) 
      It is designed for Win7+ operating systems with AERO enabled! E.g. on WinXP machines some functions are not working properly and might crash the application!
      AV scanners may have a negative impact the execution of compiled exe and might report any malware. I guarantee that there is no malicious code in the source code / exe!!! 
      Main GUI:

       
       
      About Intro:

       
       
      Basic Image Editor:

       
       
      Watermark:

       
       
      Click link for an enhanced version of Watermark Image.
      Credits:
      main code by UEZ additional code (alphabetical order) by Authenticity, AutoItObject Team, Eemuli, Eukalyptus, funkey, _Kurt, martin, monoceres, ProgAndy, taietel, trancexx, Ward, wolf9228 and Yashied! mesale0077 for turkish translation wakillon for french translation AZJIO for russian translation Keys:
      Main GUI:
      User your mouse to scroll preview window or
      Numpad 8: Scroll preview window up
      Numpad 2: Scroll preview window down
      Numpad 4: Scroll preview window left
      Numpad 6: Scroll preview window right
      Numpad +: zoom in preview window or mousewheel down
      Numpad -: zoom out preview window or mousewheel up
      F1: capture again on last position
      F5: refresh Windows Name list
      PRINTSCREEN: take screenshot from whole screen
      ALT+PRINTSCR: take a screenshot from active window
      F10: Undo made changes with Image Editing function
      F11: take screenshot from whole screen incl mouse cursor
      F12: take screenshot from whole screen
      Ctrl+Alt+F9 start "Grab Screen" mode
      Ctrl+Alt+F12: take a screenshot from active window using alternative screenshot functionality (beta)!
      Ctrl+r: call ruler
      Ctrl+s: save current displayed image
      Ctrl+x: exit program
      ctrl+w: call web grab input field (availabe only when Aero is enabled)
      Ctrl+i: call image editor
      Ctrl+m: call watermark editor
      Ctrl+z: undo
      Only available on Vista+ os: double click with rmb on list items to use alternative screenshot functionality (beta)!
      When 'Grab Screen' is clicked you can hold down the ctrl key to switch to 'grab controls' mode. Control under mouse will be framed red.
      ctrl + shift will take the screenshot of appropriate control. To capture GUI menues you can press rmb which simulates the lmb. When a menu is opened press shift additionaly to capture it.
      Press and hold only the shift key to capture any region on the desktop using freehand capturing - release it so capture marked regions!
      Or just mark resizeable area which you want to grab. Press CTRL key to grab marked area or right mouse button to capture the marked area every x seconds for a duration of y seconds.
      When saving the image just enter the extension you whish to use (*.jpg;*.png;*.bmp;*.gif;*.tif;*.pdf). Big thanks to taietel for his PDF UDF!
      Image Editor:
      s: save
      c: copy
      n: send
      h: highlighter
      p: pen
      r: rectangle
      e: ellipse
      a: arrow
      o: color
      t: text
      g: text config
      Ctrl+z: undo
      Watermark editor:
      Ctrl+z: undo
       
      To start the app minimized just call it "Windows Screenshooter.exe /min"
      Maybe it is useful for someone...
      Any kind of comment is welcome.
      Br,
      UEZ
      Change log:
       
    • Xandy
      By Xandy
      I'm listing the error message strings, and roughly matching the error code
      Is this how to do error reporting?  Is there a more simple way I don't know about?
      I realise I might not need to trap @error inside $error.  I like it this way b/c I have no fear of overwriting @error now; I don't even use it.
      Func Send_Connect($address, $port)     $socket = TCPConnect($address, $port)     $error = @error     If $error <> 0 Then         Local $aError[4] = ["-2 not connected.", _                             "1 IPAddr is incorrect.", _                             "2 port is incorrect."]         $aError[3] = "10060 Connection timed out."         If $error < 0 Then $error = 0         If $error > 2 Then $error = 3         MsgBox(0, "TCP Connect Error", $aError[$error], 0)         $socket = 0     EndIf     Return $socket EndFunc
    • Spartan117
      By Spartan117
      Hi everyone,
      I am wondering if is there any autoit function that make the program ignore errors and move on and resume correct lines?
      Thank you
    • c.haslam
      By c.haslam
      I think that _GDIPlus_ImageGetPropertyItem should return a Property Item that can readily be set as a property of another image. Why would one want to do this? A script might (as one of mine does) edit an image of a .jpg file then write the result to a .jpg file. In editing it, in my case, the number of horizontal and vertical pixels change, and the date/time edited should be set as a property. All other property items remain the same. Other GDI+ users may change other properties.
      So an approach is to copy all the property items from image1 to image2, then update a few properties.
      M$ provides a Property Item class (id, length, pointer to an array of values) but _GDIPlus_ImageGetPropertyItem returns something different.
      I think that, wherever reasonable, UDFs that are wrappers for M$ methods should work like M$'s methods. _GDIPlus_ImageGetPropertyItem does not do this:
      While M$ returns 2 values for a value that is a ratio of 2 numbers,  _GDIPlus_ImageGetPropertyItem returns numerator/denominator as a single value (often a Double). _GDIPlus_ImageSetPropertyItem (when included in GDIPlus.au3) will be unable to set ratio property items properly because it cannot know what the numerator and denominator are. So copying such property items will not work properly. M$ has a Void* buffer where the buffer is an array of values but _GDIPlus_ImageGetPropertyItem() returns the values in the same 1-d array as id, length and type. M$'s approach produces a 1-d array with the same number of elements for all property items while _GDIPlus_ImageGetPropertyItem produces a 1-d array with various numbers of elements. To me, this is not good programming practice. For a photo from a Sony camera, the worst case has 1-d array with 67 elements. When combined into a 2-d array with the property items of all properties, there are 66 rows and 67 columns, with many elements not used. So I suggest that _GDIPlus_ImageGetPropertyItem look like this:
      ; #FUNCTION# ==================================================================================================================== ; Name ..........: cGDIPlus_ImageGetPropertyItem ; Description ...: Gets a specified property item (piece of meta data) from an Image object ; Syntax ........: cGDIPlus_ImageGetPropertyItem($hImage, $iPropID) ; Parameters ....: $hImage - Pointer to an image object ; $iPropID - Identifier of the property item to be retrieved ; Return values .: Success: Array containing the values of the property item ; [0] - identifier ; [1] - size, in bytes, of the value array ; [2] - type of value(s) in the value array ; [3] - value array ; Failure: Sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPID_ERR*). ; Author ........: Eukalyptus ; Modified ......: c.haslam ; Remarks .......: types: unsigned byte = 1, ASCII string = 2, unsigned short = 3, unsigned long = 4, ; unsinged rational = 5, undefined = 7, signed long = 9, signed rational = 10 ; Related .......: _GDIPlus_ImageGetPropertyIdList ; Link ..........: https://msdn.microsoft.com/en-us/library/windows/desktop/ms535390(v=vs.85).aspx, ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms534493(v=vs.85).aspx, ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms534414(v=vs.85).aspx ; Example .......: Yes ; =============================================================================================================================== Func cGDIPlus_ImageGetPropertyItem($hImage, $iPropID) Local $iSize = __GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) If @error Then Return SetError(@error, @extended, -1) Local $tBuffer = DllStructCreate("byte[" & $iSize & "];") Local $pBuffer = DllStructGetPtr($tBuffer) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetPropertyItem", "handle", $hImage, "uint", _ $iPropID, "uint", $iSize, "struct*", $tBuffer) If @error Then Return SetError(@error, @extended, -1) If $aResult[0] Then Return SetError(10, $aResult[0], False) Local $tPropertyItem = DllStructCreate("int id; int length; short type; ptr pvalue;", $pBuffer) Local $iBytes = DllStructGetData($tPropertyItem, "length") Local $pValue = DllStructGetData($tPropertyItem, "pvalue") Local $aRet[4] Local $type = DllStructGetData($tPropertyItem,'type') Local $tValues, $iValues Switch $type Case 2 ;ASCII String $iValues = 1 $tValues = DllStructCreate("char[" & $iBytes & "];", $pValue) Case 3 ;Array of UShort $iValues = Int($iBytes / 2) $tValues = DllStructCreate("ushort[" & $iValues & "];", $pValue) Case 4, 5 ;Array of UInt / Fraction $iValues = Int($iBytes / 4) $tValues = DllStructCreate("uint[" & $iValues & "];", $pValue) Case 9, 10 ;Array of Int / Fraction $iValues = Int($iBytes / 4) $tValues = DllStructCreate("int[" & $iValues & "];", $pValue) Case Else ;Array of Bytes $iValues = 1 $tValues = DllStructCreate("byte[" & $iBytes & "];", $pValue) EndSwitch $aRet[0] = DllStructGetData($tPropertyItem,'id') $aRet[1] = $iBytes $aRet[2] = $type Local $aVals[$iValues] If $type=2 Or $type=7 Then ; ASCII string or undefined $aVals[0] = DllStructGetData($tValues,1) Else For $i = 0 To $iValues-1 $aVals[$i] = DllStructGetData($tValues,1,$i+1) Next EndIf $aRet[3] = $aVals Return $aRet EndFunc And here is an example:
      #include <GDIPlus.au3> #include <Array.au3> Example() Func Example() _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile(RegRead((@AutoItX64 = True ? "HKLM\SOFTWARE\Wow6432Node\AutoIt v3\AutoIt" : "HKLM\SOFTWARE\AutoIt v3\AutoIt"), "InstallDir") & "\Examples\GUI\Torus.png") If @error Then _GDIPlus_Shutdown() MsgBox(16, "", "An error has occured - unable to load image!", 30) Return False EndIf Local $ar = _GDIPlus_ImageGetPropertyIdList($hImage) Local $vPropNbrs[UBound($ar,1)-1] ; Extract ID numbers For $i = 1 To UBound($ar,1)-1 $vPropNbrs[$i-1] = $ar[$i][0] Next ; Get all property items Local $aPropItems[UBound($vPropNbrs)][4],$vPropItem For $i = 0 To UBound($vPropNbrs)-1 $vPropItem = cGDIPlus_ImageGetPropertyItem($hImage,$vPropNbrs[$i]) For $j = 0 To 3 $aPropItems[$i][$j] = $vPropItem[$j] Next Next ; Collapse values arrays so _ArrayDisplay can display them Local $ar = $aPropItems For $i = 0 To UBound($aPropItems,1)-1 $ar[$i][0] = '0x'&Hex($ar[$i][0],4) $ar[$i][3] = '' For $j = 0 To UBound($aPropItems[$i][3])-1 $ar[$i][3] &= ($aPropItems[$i][3])[$j]&'|' Next $ar[$i][3] = StringTrimRight($ar[$i][3],1) Next _ArrayDisplay($ar) _GDIPlus_Shutdown() EndFunc Unfortunately this example (based on one now in the Help) does not exercise most of the item types, but I do not know of a file with EXIF metadata that is on most PCs. I have tested this code by updating and adding property items to torus.jpg and to a photo taken by a Sony camera. The code for implementing and calling _GDIPlus_ImageSetPropertyItem will be fairly simple [see below].
       
      Your thoughts?
       
×