M
M
mastersoftna2011-11-11 14:12:21
Delphi
mastersoftna, 2011-11-11 14:12:21

Passing HBitmap from Delphi dll to C# application?

Welcome all. The problem is the following.
It is necessary to pass the path to the file to the Delphi dll, the dll must draw a bitmap from this file and pass the HBitmap to the C# application. There is a TImage in the dll, I draw on it and pass TImage.Picture.Bitmap.Handle. In the receiving application, I draw the image using HBitmap. But it is not drawn, my pictureBox.Image is filled with just a white background, but if before drawing and passing the handle to the dll, put ShowMessage or show a modal form, everything is normally drawn. What is the problem?
Tried to pass a pointer to the first byte of the image in memory and the size of the image. The same.
And tell me, you can somehow change the following code, so as not to collect the array by bytes, but immediately get it.

byte dd;<br/>
 byte* ddd = &dd;<br/>
 ddd = (byte*)LibWrap.TRGOpen(&quot;D:\\111.trg&quot;, ref size);<br/>
 byte[] img = new byte[size];<br/>
 for (int i = 0; i &lt; size; i++)<br/>
 {<br/>
 byte t = *(ddd + i);<br/>
 img[i] = t;<br/>
 }<br/>

dll call:
public unsafe class LibWrap<br/>
 {<br/>
 [DllImport(&quot;TRGA.dll&quot;)]<br/>
 public static extern void* TRGOpen([MarshalAs(UnmanagedType.LPStr)] string str, ref int size);<br/>
 }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2011-11-11
@GavriKos

If you consistently pass paths to the dll, draw and pass the handler back, then perhaps the library simply has not yet had time to load and draw.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question