I have a Delphi function in a dll written like this:
function LensFlare(Bitmap: TBitmap; X, Y: Int32; Brightness: Real): TBitmap; StdCall;
Begin
// ...
Result := Bitmap;
End;
I want to use it in C#, I have tried this but I was not successful:
[DllImport("ImageProcessor")]
static extern Bitmap LensFlare(Bitmap bitmap, int x, int y, double Brightness);
private void button1_Click(object sender, EventArgs e)
{
Bitmap b = new Bitmap(@"d:\a.bmp");
pictureBox1.Image = LensFlare(b, 100, 100, 50); // Error!
}
Error: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
How can I do this?
You can't use this function. It's not even safe to use between two Delphi modules unless you use packages. You cannot pass native Delphi classes across a module boundary like that.
You'll need to switch to an interop friendly type. The obvious option is to use an HBITMAP
. You will need to modify the Delphi library. If you don't have the source you will need to contact the original developer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With