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

[INCLUDE]
Unicode
OLEInterface_CallFunction
OLEInterface_Release
OLEFreePicture

[CODE]
Public Function OLELoadPictureFromFile(ByVal Filename As String, ByRef hBitmap As Long) As Long
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim hFile As Long
  Dim lpMem  As Long
  Dim xLongA1(3) As Long
  Dim xType1 As OLELoadImageIData
  
  hBitmap = 0&
  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
      xType1.hMemG = GlobalAlloc(2&, xLong1)
      If Not xType1.hMemG = 0& Then
        lpMem = GlobalLock(xType1.hMemG)
        If lpMem Then
          If ReadFile(hFile, ByVal lpMem, xLong1, xLong2, 0&) = 0& Then
            Call GlobalUnlock(xType1.hMemG)
            Else
            Call GlobalUnlock(xType1.hMemG)
            If xLong1 = xLong2 Then
              If CreateStreamOnHGlobal(xType1.hMemG, 1&, ByVal VarPtr(xType1.IStream)) = 0& Then
                If Not xType1.IStream = 0& Then
                  xLongA1(0) = &H7BF80980 '"{7BF80980-BF32-101A-8BBB-00AA00300CAB}"
                  xLongA1(1) = &H101ABF32
                  xLongA1(2) = &HAA00BB8B
                  xLongA1(3) = &HAB0C3000
                  Call OleLoadPicture(ByVal xType1.IStream, xLong1, 0&, VarPtr(xLongA1(0)), ByVal VarPtr(xType1.IPicture))
                  If Not xType1.IPicture = 0& Then
'                    xLong1 = OLEInterface_GetProperty(xType1.IPicture, 8& * 4&)
                    xLong1 = 0&
                    'Stop
                    If OLEInterface_CallFunction(xType1.IPicture, 12&, VarPtr(xLong1)) = 0& Then
                    'Stop
                      If Not xLong1 = 0& Then
                        OLELoadPictureFromFile = LocalAlloc(0&, OLELoadImageIDataLen)
                        If Not OLELoadPictureFromFile = 0& Then
                          Call RtlMoveMemory(ByVal OLELoadPictureFromFile, xType1, OLELoadImageIDataLen)
                          hBitmap = xLong1
                          GoTo Success
                          End If
                        End If
                      End If
                    Call OLEInterface_Release(xType1.IPicture)
                    End If
                  Call OLEInterface_Release(xType1.IStream)
                  End If
                End If
              End If
            End If
          End If
        Call GlobalFree(xType1.hMemG)
        End If
      End If
Success:
    Call CloseHandle(hFile)
    End If
  End Function