简体   繁体   中英

HBITMAP *Bitmap to .net Bitmap

I have a Dll and the header file for it, and I'm trying to create a COM wrapper in C++ to use in C#.
For most of functions it was very simple since they were returning int or string .

I have this struct in the header file.

virtual HRESULT STDMETHODCALLTYPE GetBMP( 
            int Width,
            int Height,
            HBITMAP *Bitmap) = 0;

My problem is that since I'm way out of my league with C++ I don't know how to convert the HBITMAP to something more appropriated to .net style

Thanks in advance, and please forgive me if wrote stupid things

UPDATE: I tried something like this :

HBITMAP GetBMP(int Width, int Height)
{

    HBITMAP bm = 0; 
    m_piHelper->GetBMP(Width,Height,&bm);   
    return bm ;

}

The problem obviously is after that in c# how convert from 'HBITMAP__*' to 'System.IntPtr to use it with bitmap.fromHbitmap

The parameter should be out IntPtr .

Then you can create an additional function that will call GetBMP and then call Bitmap.FromHbitmap to return a bitmap. Such function must then DeleteObject the original hbitmap .

您也许应该尝试System.IntPtr。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM