DLL,MFC,Bitmaps

H

Hilton

Hi,

I have an MFC DLL that reads a file and generates a bitmap which I then need
to display in my C# app. This is a CF 1.0 app (so no Graphics.GetDC method
unless I use GraphicsEx). I have two plans:

Plan A:
The C# app passes in the file name and some other parameters to the DLL.
Then the app gets the image's width and height from the DLL and (in the C#
world) does a new Bitmap (w, h). The app then passes this bitmap back to
the DLL and the DLL draws into it. This way, the Bitmap's memory management
is done in C# and the DLL is only used to draw into the bitmap, not to
create/dispose the bitmap.

Plan B:
The C# all passes in the filename and some other parameters to the DLL and
gets back a bitmap. The DLL would create/dispose the bitmap.

Please let me know what you think of these two approaches (or if there is a
third). Also, if you can help with the PInvoke stuff that would be
appreciated. I read that I can pass a C# Graphics object in as a CDC
pointer, but that doesn't seem to work. Also, what would be the cherry on
top is if I could force the image to an indexed image to save memory.

Any ideas, comments, URLs, example code very very very much appreciated.

Thanks,

Hilton
 
G

Guest

Go with A. If you go with B then you have a huge potential problem of
cleanup of resources as the DLL must be explicitly told when to release the
resources, and it could be easy to miss and end up with a nasty leak that is
tough to track down.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top