开发者

C# Marshal / Pinvoke CBitmap?

开发者 https://www.devze.com 2022-12-11 21:24 出处:网络
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this:

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class.

My import looks like this:

[DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr GetBitmap(System.IntPtr hwnd, int nBMPWIDTH, int nBMPHEIGHT);

The H file section looks like:

Cbitmap* GetBitmap(HWND hwnd,int nBMPWIDTH,int nBMPHEIGHT);

开发者_如何学GoHow do I go about converting the Cbitmap into something I can display in C#?

Many thanks.


The closest API in the .NET Framework is Image.FromHbitmap, but this would require you to extract the HBITMAP from the CBitmap, which you can't do in C# (at least not without knowing the internals of CBitmap). If it's possible for you to modify your C++ GetBitmap function to return the HBITMAP rather than the CBitmap wrapper, that would be the easiest solution. Is that an option for you?

0

精彩评论

暂无评论...
验证码 换一张
取 消