Recent

Author Topic: IMPORTING A DLL  (Read 3264 times)

stephb

  • Newbie
  • Posts: 2
IMPORTING A DLL
« on: May 16, 2021, 07:06:23 pm »
My system is Win10 and Lazarus 2.0.10 with freepascal 3.2.0.

I have successfuly converted a Delphi 7 project. This project makes use of two Windows dll's. The following code worked successfully when compiled with Delphi, but not with Lazarus. Lazarus build is successful so syntax seems OK, it is execution that is problematic.

the variable Wes5Handle is returned as a zero so the message 'Unable to load Wes5ENG.dll' is displayed.

Code is below, any input would be appreciated.

  Wes5Handle := LoadLibrary('Wes5ENG.dll');
  if Wes5Handle <> 0 then
    @ftn_Wes5ENG := GetProcAddress(Wes5Handle,'_ftn_wes5eng@116')
  else
    MessageDlg('Unable to load Wes5ENG.dll',mtError,[mbAbort],0);
  if (@ftn_Wes5ENG = nil) then
    MessageDlg('Could not import function from Wes5ENG.dll',mtError,[mbAbort],0);

 

MarkMLl

  • Hero Member
  • *****
  • Posts: 6646
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: IMPORTING A DLL
« Reply #2 on: May 16, 2021, 07:26:57 pm »
You did not mention if the DLL is 32-bit or 64-bit, nor did you say if your application matches it. I guess they do not match.

stephb

  • Newbie
  • Posts: 2
Re: IMPORTING A DLL
« Reply #3 on: May 16, 2021, 08:31:14 pm »
My apologies for not giving all that detail. The dll was developed pre-2008 in FORTRAN, most probably 32-bit. I used stdcall, had to convert all arrays to C.

Lazarus now (I assume) is 64 bit, I haven't checked, just installed.

Problem is I only have Intel 32-bit compiler, will now try and see if I can compile with gfortran, I have no experience with grfortran.

Thanks again




marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: IMPORTING A DLL
« Reply #4 on: May 16, 2021, 08:56:04 pm »
Both sides (application and dll must be the same, either 32-bit or 64-bit).

So upgrade DLL or change lazarus edition

 

TinyPortal © 2005-2018