Need help understanding enums with Windows calls

I’m trying to grab the default application icon for use elsewhere in my app. Since it is going to be used in several apps I’m doing, I want it to be generic. I’m using the following Windows Declare function and code. The variable info and its data are being defined and sourced elsewhere.

[code]Declare Function DrawIconEx Lib “User32” (hDC As Integer, xLeft As Integer, yTop As Integer, hIcon As Integer, cxWidth As Integer, _
cyWidth As Integer, StepIfAniCur As Integer, FlickerFreeDraw As Integer, Flags As Integer) As Boolean

Dim bool As Boolean
Dim ico As New Picture (32, 32, 32)
Dim hIcon As Integer = info.Int32Value (0)
#If XojoVersion < 2019.2 Then
Bool = DrawIconEx (ico.Graphics.Handle (1), 0, 0, hIcon, 32, 32, 0, 0, &h3) ’ This works
#Else
Bool = DrawIconEx (ico.Graphics.HandleTypeHDC, 0, 0, hIcon, 32, 32, 0, 0, &h3) 'This fails
#Endif[/code]
The first version, for 2019r1.1 and earlier, works fine. The second version, for 2019r2, fails in execution but not at compile time.

I guess I don’t really understand the translating of enums in cases like this or, perhaps, I’ve encountered a bug that I just don’t know enough to be able to recognize. Either way, if someone could point me in the right direction I would appreciate it.

Would it not be:
ico.Graphics.Handle(Picture.Graphics.HandleTypeHDC)

[quote=463536:@Kevin Gale]Would it not be:
ico.Graphics.Handle(Picture.Graphics.HandleTypeHDC)[/quote]
Not in pure 2019r2 since Handle has been deprecated in favor of using the enums. Both

ico.Graphics.Handle(Picture.Graphics.HandleTypeHDC)

and

ico.Graphics.Handle (1)

work but flag deprecated messages.

When you use r2 and onwards g.Handle with an enum will return a ptr not an integer so you need to move your declare into the #If and alter it:

#If XojoVersion < 2019.02 Declare Function DrawIconEx Lib "User32.dll" Alias "DrawIconEx" (hdc As Integer, xLeft As Int32, yTop As Int32, hIcon As Integer, cxWidth As Int32, cyWidth As Int32, istepIfAniCur As UInt32, hbrFlickerFreeDraw As Integer, diFlags As UInt32) As Int32 Call DrawIconEx(g.Handle(1), 0, 0, icon, 0, 0, 0, 0, DI_NORMAL) #Else Declare Function DrawIconEx Lib "User32.dll" Alias "DrawIconEx" (hdc As Ptr, xLeft As Int32, yTop As Int32, hIcon As Integer, cxWidth As Int32, cyWidth As Int32, istepIfAniCur As UInt32, hbrFlickerFreeDraw As Integer, diFlags As UInt32) As Int32 Call DrawIconEx(g.Handle(Graphics.HandleTypes.HDC), 0, 0, icon, 0, 0, 0, 0, DI_NORMAL) #EndIf

This might be what you need, I don’t know if I posted it on the forum, I wrote it a while back for someone, see Window1.Open on how to call it.

https://www.dropbox.com/s/vn4p1kurp4o5yce/TestResourceSmallForAPI2.xojo_binary_project?dl=0

Thanks, Julian. That told me what I need to know.