Recent

Author Topic: Internal Error Using CSharp DLL from Lazarus  (Read 808 times)

ADMGNS

  • New Member
  • *
  • Posts: 32
  • keep it simple and smart
Internal Error Using CSharp DLL from Lazarus
« on: June 23, 2024, 01:17:16 am »
hello

I am trying to use hqxSharp library written in CSharp like below to scale up an image by 4, but mister Lazarus says "Compilation raised exception internally". I don't understand the problem what.. Pls help.. Thanks

Code: Pascal  [Select][+][-]
  1. type
  2.   IHqxSharp = interface
  3.   ['{e23ca469-25ad-4601-83d0-fcefb0193147}']
  4.   end;
  5.  
  6.   type THqxSharp = type class(IHqxSharp)
  7.     bmpInput: TBitmap;
  8.     bmpOutput: TBitmap;
  9.     //function Scale4(bitmap: TBitmap): TBitmap; stdcall;
  10.     function Run(scale: integer = 4): TBitmap; stdcall;
  11.   end;
  12.  
  13. procedure TfrmMain.cmdHq4Click(Sender: TObject);
  14. var
  15.   hqx: THqxSharp;
  16. begin
  17.   hqx := THqxSharp.Create;
  18.  
  19.   with hqx do
  20.   begin
  21.     bmpInput := TBitmap.Create;
  22.     bmpInput.Assign(imgInput.Picture.Bitmap);
  23.  
  24.     bmpOutput := TBitmap.Create;
  25.     bmpOutput.Assign(imgInput.Picture.Bitmap);
  26.  
  27.     Run(3);
  28.  
  29.     imgOutput.Picture.Bitmap.Assign(bmpOutput);
  30.   end;
  31. end;
  32.  


Fibonacci

  • Sr. Member
  • ****
  • Posts: 453
  • Internal Error Hunter
Re: Internal Error Using CSharp DLL from Lazarus
« Reply #1 on: June 23, 2024, 01:28:39 am »
Seems fixed in trunk, the error there is
Code: Pascal  [Select][+][-]
  1. Error: Syntax error, "identifier" expected but "CLASS" found
Which goes away of you change
Code: Pascal  [Select][+][-]
  1. type THqxSharp = type class(IHqxSharp)
to
Code: Pascal  [Select][+][-]
  1. type THqxSharp = class(IHqxSharp)

jamie

  • Hero Member
  • *****
  • Posts: 6381
Re: Internal Error Using CSharp DLL from Lazarus
« Reply #2 on: June 23, 2024, 01:38:47 am »
I can be almost 100% sure, you still have a lot of code rewriting ahead of you. :o

Basically, the bitmaps the sharp lib is expecting is most likely a Handle to a Windows Type bitmap. What you are supplying is a lazarus (LCL) component which isn't the same.

 Now, you maybe able to extract the Handle from that instead?

The only true wisdom is knowing you know nothing

ADMGNS

  • New Member
  • *
  • Posts: 32
  • keep it simple and smart
Re: Internal Error Using CSharp DLL from Lazarus
« Reply #3 on: June 23, 2024, 02:01:20 am »
Hello

Could it be version problem?? Mine is Lazarus is ver 3.0, on Win10.

Actually at side of CSharp, definition is a class type.. and output is visible COM object in a dll.. (see attch) So, but, at Lazarus side, it must be class 'type' derived from interface (via with an GUID)..

Now.. When I've changed it by your suggestion, this time mister Lazarus says rightly "No matching implementation for interface method 'QueryInterface(constref TGuid;out <Formal type>):LongInt; StdCall;' found"

Perhaps, the best way might be do exporting the library from ground to FPascal/Lazarus..

Thanks

jamie

  • Hero Member
  • *****
  • Posts: 6381
Re: Internal Error Using CSharp DLL from Lazarus
« Reply #4 on: June 23, 2024, 02:25:11 am »
You need to build the class a little differently.
Code: Pascal  [Select][+][-]
  1.  THqxSharp =  class(TIntegerFacedObject, IHQxSharp)
  2.  ....
  3. End;

May help
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6381
Re: Internal Error Using CSharp DLL from Lazarus
« Reply #5 on: June 23, 2024, 02:49:34 am »
This may also help, too.

Code: Pascal  [Select][+][-]
  1.   IHqxSharp = interface(IUnknown)
  2.   ['{e23ca469-25ad-4601-83d0-fcefb0193147}']
  3.   end;
  4.  
  5.  
The only true wisdom is knowing you know nothing

myisjwj

  • Jr. Member
  • **
  • Posts: 71
Re: Internal Error Using CSharp DLL from Lazarus
« Reply #6 on: June 23, 2024, 05:03:37 am »
Is it possible that C # is managed code, and when loading DLLs in Lazarus, the libraries required for C #'s DLL are not loaded into the main program, such as NET Framework, etc.
The DLL generated by calling VC, C++, etc. is unmanaged code and can be executed without loading other DLLs.
C # has this problem, and a large part of the reason for abandoning C # back then was that C # is managed code.

 

TinyPortal © 2005-2018