How to use the Tbitmap32 (Delphi) type in a DLL called in C++?

Asked

Viewed 74 times

0

Hello!

I need to create a DLL in Delphi, to use it in a program written in C++. This DLL shall handle an image (obtained by means of path passed as a function parameter). However, I’m having trouble loading the image into the DLL; the program breaks when there is any call related to the image. I’m using a variable of the type TImage32 (img : TImage32); this variable shall be assigned a TBitmap32 (img.Bitmap := TBitmap32.Create) and finally the image should be loaded using img.Bitmap.LoadFromFile(path).

Tests I did:

  • I executed the DLL, from the C++, with parts that don’t use images. This worked properly;

  • I executed the same section, inserting the line img.Bitmap := TBitmap32.Create;. That failed on the mentioned line.

Is there any trick to use images in DLL at Delphi?

OBS1: I didn’t post code because that’s not really the problem.

OBS2: my experience with Delphi is void as well as with creation of DLL.

Thank you very much!

  • At first it is not to have great secrets. You come to present what exception is happening? In case you do not blow the exception clearly in your application in C++ you can save the exception in a file log to have more details than this happening.

  • The image is a file on your computer, right? The path is correct? The file is in the expected format (in this case, Bitmap 32 bits per pixel)? I’m no expert on Delphi, but when I deal with images, these are the most common mistakes...

  • 1

    It shouldn’t be: "img := Tbitmap32.Create;"?

  • Aren’t you jumping the gun on your OBS1? Most likely it’s the code... there are no tricks in DLLS. The most that could happen was differences in the types of input data of the functions. For example with C# it is more difficult, in principle with C++ it would be direct

1 answer

0

Apparently this using a third party public, at that point it is difficult to help, but in theory was created based on Timage pattern.

If this is the case the creation is with error and the problem is exactly ai, an exception will be generated and your DLL has no treatment.

Try to use the Timage native following this format:

var
  vTeste: TImage;
begin
  vTeste := TImage.Create(Self);
  vTeste.Picture.Bitmap.LoadFromFile('C:\temp\Teste.bmp');

Here worked normally.

Note that, first we create the Object, then feed its properties. In your posted case I believe the problem is exactly this!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.