Recent

Author Topic: Porting DLL wrapper from Delphi to Lazarus - app crashes  (Read 7845 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Porting DLL wrapper from Delphi to Lazarus - app crashes
« Reply #15 on: January 17, 2018, 04:57:24 pm »
Nope.

In Pascal it needs at least one fully qualified declaration. Either in interface or in implementation. FreePascal is more strict than Delphi.
Only in very simple scenario's it works like you wrote and not in all Delphi versions.
« Last Edit: January 17, 2018, 05:18:43 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Tomas Silva

  • New Member
  • *
  • Posts: 24
Re: Porting DLL wrapper from Delphi to Lazarus - app crashes
« Reply #16 on: January 17, 2018, 05:36:22 pm »
Well, fine. As I said I've been working solidly with this syntax for years.

Anyway adding the function name qualifier changed nothing on my application's behaviour.

balazsszekely

  • Guest
Re: Porting DLL wrapper from Delphi to Lazarus - app crashes
« Reply #17 on: January 17, 2018, 05:45:48 pm »
Hi Tomas Silva,

Since the first function loads fine, I assume bitness is not an issue. You don't try to load a 32 bit dll from a 64 bit application or vice versa. I would try to load the dll dynamically from a separate application, like this:
Code: Pascal  [Select][+][-]
  1. uses dynlibs, LCLType;
  2.  
  3. procedure TForm1.Button1Click(Sender: TObject);
  4. type
  5.   TMyFunction = function(AParam: Integer): Integer; stdcall;
  6. var
  7.   LibHandle: TLibHandle;
  8.   FarProc: TFarProc;
  9.   MyFunction: TMyFunction;
  10. begin
  11.   LibHandle := LoadLibrary('FullPathToYourLibrary');
  12.   if LibHandle <> NilHandle then
  13.   begin
  14.     FarProc := GetProcedureAddress(LibHandle, 'MyFunction');
  15.     if FarProc <> nil then
  16.     begin
  17.       MyFunction := TMyFunction(FarProc);
  18.       MyFunction(15);
  19.     end;
  20.   end;
  21. end;

Change "MyFunction" declaration and "FullPathToYourLibrary" then debug your application. Which is the line where the error occurs(if any)?


regards,
GetMem
« Last Edit: January 17, 2018, 05:47:57 pm by GetMem »

Tomas Silva

  • New Member
  • *
  • Posts: 24
Re: Porting DLL wrapper from Delphi to Lazarus - app crashes
« Reply #18 on: January 17, 2018, 05:51:24 pm »
Thanks GetMem, I'll try that right away.

Regards!

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Porting DLL wrapper from Delphi to Lazarus - app crashes
« Reply #19 on: January 17, 2018, 06:18:07 pm »
Mind you: still case sensitive! Good example GetMem.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Tomas Silva

  • New Member
  • *
  • Posts: 24
Re: Porting DLL wrapper from Delphi to Lazarus - app crashes
« Reply #20 on: January 17, 2018, 06:49:09 pm »
Hey guys,

No joy. Still fails at the exact same spot. Just to be sure, I used Dumpbin to check the exact spelling of the functions, and they were correct to begin with.

Any more ideas what could be causing this? What boggles my mind is that it works right away as soon as I compile it through Delphi. Could there be any weird compiler directive messing my DLL call?

Thank you!

balazsszekely

  • Guest
Re: Porting DLL wrapper from Delphi to Lazarus - app crashes
« Reply #21 on: January 17, 2018, 07:08:11 pm »
So it fails at  MyFunction(15) ? This is highly suspicious, especially since the first function works fine. In my opinion the culprit is not Lazarus. I quote you:
Quote
a sequence of functions is called to connect to a server and set up a listening channel which then receives connections.
I'm almost certain the error is caused by some AV, Firewall, or not enough privileges. Did you try to white list Lazarus? Disable AV?

Tomas Silva

  • New Member
  • *
  • Posts: 24
Re: Porting DLL wrapper from Delphi to Lazarus - app crashes
« Reply #22 on: January 17, 2018, 07:18:22 pm »
Hi GetMem, I totally see where you're coming from. I'd have guessed that too, but I checked and it's not that.

I have no AV on my developing machine, and the company's firewall never makes a fuss about any new executable trying to reach the network. Plus I copied the executable into a test machine within the customer's network, the same place where I tested the Delphi version.

It's really strange that it should work by Delphi and not by Lazarus, but that really seems to be the case.

I would try to port it to C# but it's such a hassle, especially because in the end it's supposed to work as a Windows service so VS adds a lot of overhead to the work. I'm losing hope on Lazarus for this though.

balazsszekely

  • Guest
Re: Porting DLL wrapper from Delphi to Lazarus - app crashes
« Reply #23 on: January 17, 2018, 07:22:18 pm »
@Tomas Silva
Any chance to upload somewhere the dll so we can run a few tests?

Ps: Another idea, create two exe one with Lazarus one with Delphi, keep it to minimum(only loading the dll and call the function, nothing else). Compare asm code with Ollydbg for example. You can also run with Olly line be line both exe. Maybe it will reveal something interesting.
« Last Edit: January 17, 2018, 07:36:03 pm by GetMem »

Tomas Silva

  • New Member
  • *
  • Posts: 24
Re: Porting DLL wrapper from Delphi to Lazarus - app crashes
« Reply #24 on: January 17, 2018, 07:36:13 pm »
@GetMem, unfortunatelly I can't really do that since the DLL is part of a copyrighted SDK. Anyway it doesn't work without specific platforms of Avaya's which the software has to connect to.

If you are, per chance, a member of Avaya DevConnect you could download it via the Devconnect website. It's called the "Avaya HDX SDK".

There is actually another option in the same SDK, a CORBA connector, which seems to be extremely messy, but I might have to resort to that.

Tomas Silva

  • New Member
  • *
  • Posts: 24
Re: Porting DLL wrapper from Delphi to Lazarus - app crashes
« Reply #25 on: January 17, 2018, 07:37:26 pm »
I'll try the Ollydbg approach though - could really help.

Thank you again!

balazsszekely

  • Guest
Re: Porting DLL wrapper from Delphi to Lazarus - app crashes
« Reply #26 on: January 17, 2018, 07:41:21 pm »
Quote
If you are, per chance, a member of Avaya DevConnect you could download it via the Devconnect website. It's called the "Avaya HDX SDK".
No. I'm not a member unfortunately.

Quote
I'll try the Ollydbg approach though - could really help.
Thank you again!
You're welcome, unfortunately there is little we can do without the dll.   

 

TinyPortal © 2005-2018