[API]
FindResourceA
LoadResource
SizeofResource
LockResource
RtlMoveMemory

[INCLUDE]
GenericInit

[CODE]
' -1 = lngfile (=true)
'  0 = intonly
Public Function LoadResEx_Data(ByVal resName As Variant, Optional ByVal resType As Variant = "BIN", Optional ByVal hModul As Long) As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xChar1 As String
  Dim xChar2 As String
#If InIDE Then
  Dim xByteA1() As Byte
#End If
    
  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 = 0& Then
    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&
      LoadResEx_Data = String(xLong1, vbNullChar)
      Call RtlMoveMemory(ByVal LoadResEx_Data, xByteA1(0), xLong1)
      End If
Rs1:
    On Error GoTo 0
    Exit Function
Er1:
    Resume Rs1
    End If
#End If


  xLong1 = FindResourceA(hModul, xChar1, xChar2)
  If Not xLong1 = 0& Then
    xLong2 = LoadResource(hModul, xLong1)
    If Not xLong2 = 0& Then
      xLong1 = SizeofResource(hModul, xLong1)
      If Not xLong1 = 0& Then
        hModul = LockResource(xLong2)
        If Not hModul = 0& Then
          LoadResEx_Data = String(xLong1, vbNullChar)
          Call RtlMoveMemory(ByVal LoadResEx_Data, ByVal hModul, xLong1)
          End If
        End If
      End If
    End If
  End Function
