[INCLUDE]
CreateFile
GDIPlus_LoadImageFromHGlobal

[API]
GetFileSize
ReadFile
CloseHandle
GlobalAlloc
GlobalLock
GlobalUnlock
GlobalFree

[CODE]
Public Function GDIPlus_LoadImageFromFile(ByVal Filename As String) As Long
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xLong4 As Long
  Dim hMem As Long
  Dim ptrMem As Long

  xLong1 = CreateFile(Filename, OpenExisting, FILE_READ)
  If Not xLong1 = -1& Then
    xLong2 = GetFileSize(xLong1, xLong3)
    If xLong3 = 0& And Not xLong2 = 0& Then
      hMem = GlobalAlloc(2&, xLong2)
      If Not hMem = 0& Then
        ptrMem = GlobalLock(hMem)
        If Not ptrMem = 0& Then
          xLong4 = ReadFile(xLong1, ByVal ptrMem, xLong2, xLong3, 0&)
          Call GlobalUnlock(hMem)
          If Not xLong4 = 0& And xLong2 = xLong3 Then
            GDIPlus_LoadImageFromFile = GDIPlus_LoadImageFromHGlobal(hMem)
            GoTo NoFreeMem
            End If
          End If
        Call GlobalFree(hMem)
NoFreeMem:
        End If
      End If
    Call CloseHandle(xLong1)
    End If
  End Function
