[Lazarus] using a weird DLL

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] using a weird DLL

Free Pascal - Lazarus mailing list
I would like to use a function exported from a DLL. The DLL was written in C++ (Visual Studio 2015).

Inside the original code the function is declared as 

        public bool GetSkinFeatures(Bitmap Input_Bitmap, Rectangle ROI_Rect, double[] ExtractedFeatures)

Anybody knows how to use it from Lazarus?

This is too much for me...

Thank you

Duilio

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] using a weird DLL

Free Pascal - Lazarus mailing list
duilio foschi via lazarus <[hidden email]> schrieb am So., 31. Jan. 2021, 23:23:
I would like to use a function exported from a DLL. The DLL was written in C++ (Visual Studio 2015).

Inside the original code the function is declared as 

        public bool GetSkinFeatures(Bitmap Input_Bitmap, Rectangle ROI_Rect, double[] ExtractedFeatures)

Anybody knows how to use it from Lazarus?

Can you also show the declarations of Bitmap and Rectangle? Is the function declared inside an "extern "C"" block? 

Regards, 
Sven 

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Fwd: using a weird DLL

Free Pascal - Lazarus mailing list


for Sven:

>Is the function declared inside an "extern "C"" block? 

no

The code says:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;


namespace SkinAnalyzer
{
    public class ImageProcessing
    {
        //--------------------------------------------------------------------------------------------
        public ImageProcessing()
        {
            // init., if necessary
        }

        //--------------------------------------------------------------------------------------------
        // get the features

        public bool GetSkinFeatures(Bitmap Input_Bitmap, Rectangle ROI_Rect, double[] ExtractedFeatures)
        {
            // check the parameters
            if (Input_Bitmap == null)
                return false;
            if (Input_Bitmap.PixelFormat != PixelFormat.Format8bppIndexed &&
                    Input_Bitmap.PixelFormat != PixelFormat.Format24bppRgb &&
                    Input_Bitmap.PixelFormat != PixelFormat.Format32bppArgb &&
                    Input_Bitmap.PixelFormat != PixelFormat.Format32bppRgb)
                return false;

            // get the input pixels
            Rectangle rect1 = new Rectangle(0, 0, Input_Bitmap.Width, Input_Bitmap.Height);
            BitmapData input_data = Input_Bitmap.LockBits(rect1, ImageLockMode.ReadOnly, Input_Bitmap.PixelFormat);
            IntPtr ptr1 = input_data.Scan0;
            int bytesbpp = 0;    // bytes_per_pixel
            switch (Input_Bitmap.PixelFormat)
            {

On Mon, Feb 1, 2021 at 10:08 AM duilio foschi <[hidden email]> wrote:
I am corrected. The DLL is written in c#. It seems that Bitmap and Rectangle are common predefined/usable objects in C#.

Re Bitmap, I found these notes:
"Surely you cannot expect C# Bitmap to be binary compatible with Delphi TBitmap? You need to pass around an HBITMAP. On the Delphi side you use ReleaseHandle to get the HBITMAP. On the C# side it would be Image.FromHbitmap"

Re Rectangle, I found nothing interesting :(

However it seems natural to expect that Rectangle it is given by a pointer to a fixed array of 2 points= 4 integers= 16 bytes in all.

Thank you
Duilio

On Mon, Feb 1, 2021 at 7:52 AM Sven Barth <[hidden email]> wrote:
duilio foschi via lazarus <[hidden email]> schrieb am So., 31. Jan. 2021, 23:23:
I would like to use a function exported from a DLL. The DLL was written in C++ (Visual Studio 2015).

Inside the original code the function is declared as 

        public bool GetSkinFeatures(Bitmap Input_Bitmap, Rectangle ROI_Rect, double[] ExtractedFeatures)

Anybody knows how to use it from Lazarus?

Can you also show the declarations of Bitmap and Rectangle? Is the function declared inside an "extern "C"" block? 

Regards, 
Sven 

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Fwd: using a weird DLL

Free Pascal - Lazarus mailing list
duilio foschi via lazarus <[hidden email]> schrieb am Mo., 1. Feb. 2021, 11:22:

On Mon, Feb 1, 2021 at 10:08 AM duilio foschi <[hidden email]> wrote:
I am corrected. The DLL is written in c#. It seems that Bitmap and Rectangle are common predefined/usable objects in C#.

You can't trivially use a C# (or .NET in general) library in native code. (It essentially involves hosting the CLR and then invoking the code) 

RemObjects for example provides bridges for the managed and unmanaged code, but I don't know whether it supports Lazarus and it isn't free (as in beer) anyway. ( https://hydra.remobjects.com/hydra/default.aspx

Regards, 
Sven 

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus