Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

OleCreatePictureIndirect (oleaut32)
 
.

Summary:

VB Signature:

    <DllImport("OleAut32.dll", EntryPoint:="OleCreatePictureIndirect", ExactSpelling:=True, PreserveSig:=False)>
    Private Shared Function OleCreatePictureIndirect(<MarshalAs(UnmanagedType.AsAny)>picdesc As Object, ByRef iid As Guid, <MarshalAs(UnmanagedType.Bool)>fOwn As Boolean) As stdole.IPictureDisp
    End Function
    <DllImport("OleAut32.dll", EntryPoint:="OleCreatePictureIndirect", CharSet:=CharSet.Ansi, ExactSpelling:=True, PreserveSig:=True)>
    Private Function OleCreatePictureIndirect(ByRef pictdesc As PICTDESC, ByRef riid As Guid, fOwn As Boolean, <MarshalAs(UnmanagedType.IDispatch)> ByRef lplpvObj As Object) As Integer
    End Function

User-Defined Types:

    Private NotInheritable Class PICTDESC
        Private Sub New()
        End Sub
    <StructLayout(LayoutKind.Sequential)>
    Friend Structure PICTDESC
    Public SizeOfStruct As Integer
    Public PicType As Integer
    Public Hbitmap As IntPtr
    Public Hpal As IntPtr
    Public Padding As Integer
    Public Sub New(hBmp As IntPtr)
        SizeOfStruct = Marshal.SizeOf(GetType(PICTDESC))
        PicType = 1
        Hbitmap = hBmp
        Hpal = IntPtr.Zero
        Padding = 0
    End Sub
    End Structure

None.

        Private Enum PicType As Short
        Uninitialized = -1
        None = 0
        Bitmap = 1
        MetaFile = 2
        Icon = 3
        EnhMetaFile = 4
        End Enum

Alternative Managed API:

Do you know one? Please contribute it!

        <StructLayout(LayoutKind.Sequential)>
        Public Structure Bitmap
        Private ReadOnly SizeOfStruct As Integer
        Private ReadOnly PicType As Integer
        Private ReadOnly BitmapHandle As IntPtr
        Private ReadOnly PaletteHandle As IntPtr
        Private ReadOnly Padding As Integer

Notes:

Though this function is undoubtedly useful for other purposes, I have only seen it used to convert managed image types to the type required for use in custom Office ribbons.

        Public Sub New(input As Drawing.Bitmap)
            SizeOfStruct = Marshal.SizeOf(GetType(PICTDESC.Bitmap))
            PicType = PICTDESC.PicType.Bitmap
            BitmapHandle = input.GetHbitmap()
            PaletteHandle = IntPtr.Zero
            Padding = 0
        End Sub
        End Structure

Tips & Tricks:

Please add some!

Sample Code:

        <StructLayout(LayoutKind.Sequential)>
        Public Structure Icon
        Private ReadOnly SizeOfStruct As Integer
        Private ReadOnly PicType As Integer
        Private ReadOnly IconHandle As IntPtr
        Private ReadOnly Padding As Integer
        Private ReadOnly MorePadding As Integer
    <DllImport("OleAut32.dll", EntryPoint:="OleCreatePictureIndirect", CharSet:=CharSet.Ansi, ExactSpelling:=True, PreserveSig:=True)>
    Private Function OleCreatePictureIndirect(ByRef pictdesc As PICTDESC, ByRef riid As Guid, fOwn As Boolean, <MarshalAs(UnmanagedType.IDispatch)> ByRef lplpvObj As Object) As Integer
    End Function

        Public Sub New(input As Drawing.Icon)
            SizeOfStruct = Marshal.SizeOf(GetType(PICTDESC.Icon))
            picType = PICTDESC.PicType.Icon
            IconHandle = input.Handle
            Padding = 0
            MorePadding = 0
        End Sub
        End Structure
    End Class

None.

    <StructLayout(LayoutKind.Sequential)>
    Friend Structure PICTDESC
    Public SizeOfStruct As Integer
    Public PicType As Integer
    Public Hbitmap As IntPtr
    Public Hpal As IntPtr
    Public Padding As Integer
    Public Sub New(hBmp As IntPtr)
        SizeOfStruct = Marshal.SizeOf(GetType(PICTDESC))
        PicType = 1
        Hbitmap = hBmp
        Hpal = IntPtr.Zero
        Padding = 0
    End Sub
    End Structure

Alternative Managed API:

Do you know one? Please contribute it!

    Public Function ImageToPictureDisp(Input As Bitmap) As stdole.IPictureDisp
    Dim PictDesc As PICTDESC = New PICTDESC(Input.GetHbitmap())
    Dim Pic As Object = Nothing
    OleCreatePictureIndirect(PictDesc, GetType(stdole.IPictureDisp).GUID, True, Pic)
    Return CType(Pic, stdole.IPictureDisp)
    End Function

Notes:

Though this function is undoubtedly useful for other purposes, I have only seen it used to convert managed image types to the type required for use in custom Office ribbons.

Tips & Tricks:

Please add some!

Sample Code:

    Public Function ConvertToIPictureDisplay(input As Bitmap) As stdole.IPictureDisp
        Dim bitmap As PICTDESC.Bitmap = New PICTDESC.Bitmap(input)
        Return OleCreatePictureIndirect(bitmap, GetType(stdole.IPictureDisp).GUID, True)
    End Function

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions