字节数组到IPictureDisp

时间:2012-08-18 16:38:29

标签: image vb6 menu icons bytearray

我在资源字典中有一个图像,我想把它作为菜单的图标用SetMenuBitMaps API,所以我在资源字典中有图像的字节数组,如何将字节转换为IPictureDisp?我发现了这个:

      Private Declare Function CreateStreamOnHGlobal Lib "ole32.dll" (ByRef hGlobal As Any, ByVal fDeleteOnResume As Long, ByRef ppstr As Any) As Long
Private Declare Function OleLoadPicture Lib "olepro32.dll" (ByVal lpStream As IUnknown, ByVal lSize As Long, ByVal fRunMode As Long, ByRef riid As GUID, ByRef lplpObj As Any) As Long
Private Declare Function CLSIDFromString Lib "ole32.dll" (ByVal lpsz As Long, ByRef pclsid As GUID) As Long
Private Const SIPICTURE As String = "{7BF80980-BF32-101A-8BBB-00AA00300CAB}"
Public Function PictureFromArray(ByRef b() As Byte) As IPicture
      On Error GoTo errorhandler

      Dim istrm As IUnknown
      Dim tGuid As GUID

      If Not CreateStreamOnHGlobal(b(LBound(b)), False, istrm) Then
        CLSIDFromString StrPtr(SIPICTURE), tGuid
        OleLoadPicture istrm, UBound(b) - LBound(b) + 1, False, tGuid, PictureFromArray
      End If

      Set istrm = Nothing
      Exit Function
    errorhandler:
      Debug.Print "Could not convert to IPicture!"
    End Function

但它不适合我,它总是返回“没什么”。

0 个答案:

没有答案