[API]
FindResourceA
LoadResource
SizeofResource
LockResource
GlobalAlloc
GlobalLock
GlobalUnlock
GlobalFree
RtlMoveMemory

[INCLUDE]
GenericInit
GDIPlus_LoadImageFromHGlobal

[CODE]
Public Function GDIPlus_LoadImageFromRes(ByVal resName As Variant, Optional ByVal resType As Variant = "GIF", Optional ByVal hModul As Long = -1&) As Long
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xChar1 As String
  Dim xChar2 As String
#If InIDE Then
  Dim xByteA1() As Byte
#End If
'Stop
    
  If VarType(resName) = vbString Then
    xChar1 = resName
    Else
    xChar1 = "#" + CStr(Val(resName))
    End If
  If VarType(resType) = vbString Then
    xChar2 = resType
    Else
    xChar2 = "#" + CStr(Val(resType))
    End If
      
  If hModul = -1& Then
#If LoadResEx_SetLanguageFile Then
    hModul = LoadResEx_LanguageFile_hModule
#Else
    hModul = App.hInstance
#End If
#If InIDE Then
    If hModul = App.hInstance Then
      On Error GoTo Er1:
      If Left(resName, 1&) = "#" Then resName = Val(Mid(resName, 2&))
      If Left(resType, 1&) = "#" Then resType = Val(Mid(resType, 2&))
      xByteA1() = LoadResData(resName, resType)
      xLong1 = UBound(xByteA1())
      If xLong1 > -1& Then
        xLong1 = xLong1 + 1&
        xLong2 = GlobalAlloc(2&, xLong1)
        If Not xLong2 = 0& Then
          xLong3 = GlobalLock(xLong2)
          If Not xLong3 = 0& Then
            Call RtlMoveMemory(ByVal xLong3, xByteA1(0), xLong1)
            Call GlobalUnlock(xLong2)
            GDIPlus_LoadImageFromRes = GDIPlus_LoadImageFromHGlobal(xLong2)
            If Not GDIPlus_LoadImageFromRes = 0& Then GoTo NoFreeMemIDE
            End If
          Call GlobalFree(xLong2)
NoFreeMemIDE:
          End If
        End If
Rs1:
      On Error GoTo 0
      Exit Function
Er1:
      Resume Rs1
      End If
#End If
    ElseIf hModul = 0& Then
#If InIDE And LoadResEx_SetLanguageFile Then
    hModul = LoadResEx_LanguageFile_hModule
#Else
    hModul = App.hInstance
#End If
    End If

  If Not hModul = 0& Then
    xLong1 = FindResourceA(hModul, xChar1, xChar2)
    If Not xLong1 = 0& Then
      xLong2 = LoadResource(hModul, xLong1)
      If Not xLong2 = 0& Then
        xLong3 = SizeofResource(hModul, xLong1)
        If Not xLong3 = 0& Then
          hModul = LockResource(xLong2)
          If Not hModul = 0& Then
            xLong1 = GlobalAlloc(2&, xLong3)
            If Not xLong1 = 0& Then
              xLong2 = GlobalLock(xLong1)
              If Not xLong2 = 0& Then
                Call RtlMoveMemory(ByVal xLong2, ByVal hModul, xLong3)
                Call GlobalUnlock(xLong1)
                GDIPlus_LoadImageFromRes = GDIPlus_LoadImageFromHGlobal(xLong1)
                If Not GDIPlus_LoadImageFromRes = 0& Then GoTo NoFreeMem
                End If
              Call GlobalFree(xLong1)
NoFreeMem:
              End If
            End If
          End If
        End If
      End If
    End If
  End Function
