| yamen ajjour (6) | |||
|
0 down vote favorite i am trying to use unmanaged code from managed code i would like to provide the following function from the unmanaged code extern "C" __declspec( dllexport) HBITMAP * DetectDocumentPatter(HBITMAP* b); for now the implementation of the code just return the same parameter b i am trying to access it from .net side
but the 5th line code through a generic error occured in GDI+ any idea how can i marshal HBITMAP to .net Bitmap ! i've searched here but the content is really misleading | |||
|
|
|||
| webJose (2948) | |
|
UPDATE: The question kept ringing a bell in the back of my head so I checked. HBITMAP is a handle to a bitmap object, so the above doesn't apply entirely. It is true, though that Scan0 is not the equivalent of a bitmap handle, and this is why you get an error. | |
|
Last edited on
|
|
| andywestken (1966) | |||||
|
How about the GetHbitmap() method of Bitmap? Bitmap.GetHbitmap Method http://msdn.microsoft.com/en-us/library/1dz311e4.aspx i.e. (untested)
Andy PS Belatedly noticed that your imported function DetectDocumentPatter is working with HBITMAP*s rather than the usual HBITMAP. Any reason for that? Usually you only use a HBITMAP* for an out param. MSDN states that GetHbitmap() returns an HBITMAP and FromHbitmap takes an HBITMAP, not HBITMAP*. So you should adjust DetectDocumentPatter if possible. e.g.
DeleteObject definitely takes a handle! | |||||
|
Last edited on
|
|||||