Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2021-01

using a weird DLL

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

duilio foschi

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210131/7be61105/attachment.html>

Reply by email

Sven Barth
to duilio foschi

duilio foschi via lazarus schrieb am So.,
31. Jan. 2021, 23:23:

Show quoted text 10 lines
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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210201/c30596ef/attachment.html>

Reply by email

duilio foschi

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)
            {
AM duilio foschi wrote 41 lines
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 wrote: > duilio foschi via lazarus 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 > >>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210201/b7b6fc88/attachment.html>

Reply by email

Sven Barth
to duilio foschi

duilio foschi via lazarus schrieb am Mo.,
1. Feb. 2021, 11:22:

Show quoted text 8 lines
On Mon, Feb 1, 2021 at 10:08 AM duilio foschi 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210201/681b45c3/attachment.html>

Reply by email