Click here to Skip to main content
11,477,044 members (75,368 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
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.
Posted 12-Oct-12 5:13am
Sergey Alexandrovich Kryukov at 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 at 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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Andrewpeter at 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 at 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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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


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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 274
1 Richard Deeming 245
2 _duDE_ 165
3 Tomas Takac 150
4 Sascha Lefèvre 145
0 Sergey Alexandrovich Kryukov 7,675
1 OriginalGriff 7,246
2 Sascha Lefèvre 3,034
3 Maciej Los 2,491
4 Richard Deeming 2,305

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 13 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100