Passing a Handle to a Bitmap from a C++ DLL to a C# app using the Dll

Randy Feingersh 21 Reputation points
2021-02-03T05:44:05.537+00:00

I'm trying to pass a handle to a bitmap from a non- CLI C++ Dll that I wrote to a C# app.

Sorry it's been a while and I could use some guidance on how to approach this. I"ve seen lost of stuff on passing Bitmaps from C# to non-CLI C++ dll but nothing going the other way.

Any suggestion will be much appreciated. I can modify the C++ Dll if need be.

Thanks

Developer technologies | C++
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2021-02-03T08:29:20.927+00:00

    If you have a HBITMAP, you can represent it as an IntPtr in C# and use Image.FromHBitmap to make an image object.

    For example, you can define an exported function that returns HBITMAP. In C#, use [DllImport] attribute to access the external function. The return type will be IntPtr. It depends on details about your code.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.