Click here to Skip to main content
15,798,200 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi everyone, I want to p/invoke OleCreatePictureIndirect() function in C#, I searched it in[^] but I didnt find it, please help me solve this problem, thanks.
Sergey Alexandrovich Kryukov 12-Oct-12 12:29pm    
Why doing it, ever? Isn't GDI+ or, better, DirectX-based WPF could be more then enough for you?
Andrewpeter 12-Oct-12 22:24pm    
Thanks SA, I want to get images from dll file, this is VB6 article:

In this article I see him use OleCreatePictureIndirect() API, i want to convert that code to C# code; i cant find any information about this API with C#. Could you help me? Thank you very much.


Here is the brief implementation of what you need, I didn't test it - so you may need make some corrections:
    uint cbSizeofstruct; 
    uint picType;
    IntPtr hbitmap;
    IntPtr hmeta;
    IntPtr hicon;
    IntPtr hemf;
    HPALETTE hpal;
    HPALETTE xExt;
    HPALETTE yExt;
class RECT
    public int left;
    public int top;
    public int right;
    public int bottom;
[ComImport, System.Security.SuppressUnmanagedCodeSecurity]
interface IPicture
    int get_Handle([Out] out IntPtr pHandle);
    int get_hPal([Out] out IntPtr phPal);
    int get_Type( [Out] out short pType);
    int get_Width( [Out] out int pWidth);
    int get_Height( [Out] out int pHeight);
    int Render( 
        [In] IntPtr hDC,
        [In] int x,
        [In] int y,
        [In] int cx,
        [In] int cy,
        [In] int xSrc,
        [In] int ySrc,
        [In] int cxSrc,
        [In] int cySrc,
        [In,MarshalAs(UnmanagedType.LPStruct)] RECT pRcWBounds);
    int set_hPal( [In] IntPtr hPal);
    int get_CurDC( [Out] out IntPtr phDC);
    int SelectPicture( IntPtr hDCIn,[Out] out IntPtr phDCOut,[Out] out IntPtr phBmpOut);
    int get_KeepOriginalFormat( [Out,MarshalAs(UnmanagedType.Bool)] out bool pKeep);
    int put_KeepOriginalFormat([In,MarshalAs(UnmanagedType.Bool)] bool keep);
    int PictureChanged( );
    int SaveAsFile([In] System.Runtime.InteropServices.ComTypes.IStream pStream,
        [In,MarshalAs(UnmanagedType.Bool)] bool fSaveMemCopy,[Out] out int pCbSize);
    int get_Attributes([Out] out uint pDwAttr);
static extern int OleCreatePictureIndirect(
    [In, MarshalAs(UnmanagedType.LPStruct)] PICTDESC pPictDesc,
    [In] ref Guid riid,
    [In, MarshalAs(UnmanagedType.Bool)] bool fOwn,
    [Out] out object ppvObj);
PICTDESC _desc = new PICTDESC();
// initalize picture desc
object _object;
Guid _guid = typeof(IPicture).GUID;
if (0 == OleCreatePictureIndirect(_desc, ref _guid, true, out _object))
    IPicture _picture = (IPicture)_object;
    // Working with _picture

Share this answer
Share this answer
Andrewpeter 13-Oct-12 3:01am    
Thank you, SA. I read it, but i dont get images from C# dll (class library of C#), my dll is WIN32 dll (e.g: Shell32.dll,....). That topic (in your link) uses C# dll. I can convert all VB6 code above to C# code but the third parameter of OleCreatePictureIndirect() (it is "IPic As IPicture") - my main question is "What type of C# does equivalent with IPicture in VB6?". Thanks. My vote is 5 for your answer, hope you help me more.
Sergey Alexandrovich Kryukov 14-Oct-12 1:32am    
This is not a question of "equivalent". "IPicture", as well as most of the types (all except language aliases) do not belong in language. A type is the type. Wrong question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900