[API]
CreateStreamOnHGlobal
OleLoadPicture
GlobalAlloc
GlobalLock
GlobalUnlock
GlobalFree
RtlMoveMemory
CloseHandle
GetFileSize
ReadFile

[INCLUDE]
CreateFile

[CODE]
Public Function IPictureFromFile(ByVal Filename As String) As IPicture
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim hFile As Long
  Dim hMem  As Long
  Dim lpMem  As Long
  Dim istm As IUnknown '  IStream
  Dim xLongA1(3) As Long
  
  If IsUnicode Then
    hFile = CreateFileW(ByVal StrPtr(Filename), &H80000000, &H1&, 0&, 3&, &H20&, 0&)
    Else
    hFile = CreateFileA(Filename, &H80000000, &H1&, 0&, 3&, &H20&, 0&)
    End If
  If Not hFile = -1& Then
    xLong1 = GetFileSize(hFile, 0&)
    If Not xLong1 = 0& Then
      hMem = GlobalAlloc(2&, xLong1)
      If Not hMem = 0& Then
        lpMem = GlobalLock(hMem)
        If lpMem Then
          If ReadFile(hFile, ByVal lpMem, xLong1, xLong2, 0&) = 0& Then
            Call GlobalUnlock(hMem)
            Else
            Call GlobalUnlock(hMem)
            If xLong1 = xLong2 Then
              If CreateStreamOnHGlobal(hMem, 1&, istm) = 0& Then
                xLongA1(0) = &H7BF80980 '"{7BF80980-BF32-101A-8BBB-00AA00300CAB}"
                xLongA1(1) = &H101ABF32
                xLongA1(2) = &HAA00BB8B
                xLongA1(3) = &HAB0C3000
                Call OleLoadPicture(ByVal ObjPtr(istm), xLong1, 0&, VarPtr(xLongA1(0)), IPictureFromFile)
                GoTo Success
                End If
              End If
            End If
          End If
        Call GlobalFree(hMem)
        End If
      End If
Success:
    Call CloseHandle(hFile)
    End If
  End Function
