Recent

Author Topic: Unable to Create 64 bit DLL in Windows  (Read 9635 times)

williamda

  • Newbie
  • Posts: 5
    • Visión Tecnológica
Unable to Create 64 bit DLL in Windows
« on: July 29, 2011, 12:02:55 am »
Hello,

I´m new to Lazarus. I´m moving from Delphi looking for a 64 bit compiler. I really believe Embarcadero has lost the directions with DElphi developing and Lazarus/FPC looks more promising.

My first project is to create a 64 bit DLL in Lazarus and call it from another Lazarus application. But I get a SISEGV error whenever I try to call it with early or late binding. I´ve found that the debugger still doesn´t work in 64 bit Windows.

Creating/calling a 64 bit DLL can be done with Lazarus. I tried with oficcial release 0.93 and Lazarus trunk, but none of these worked.

--- This is the exported function

function Hola: Int64; stdcall; export;
begin
  Result := 22;
end; 


---- This is the call

// Early Binding

function Hola: Int64; external 'testhola.dll';

procedure TForm1.Button4Click(Sender: TObject);
var
  Res : Int64;
begin
  Res := Hola();
  lbLoadStatus.caption := 'Hola Retorna :' + IntToStr(res);
end; 

// Late Binding

procedure TForm1.Button3Click(Sender: TObject);
type
  THola = function(): Int64; stdcall;
var
  Hola: THola;
  res: Int64;
begin
  FDLLHandle := LoadLibrary( PChar(S) );
  if FDLLHandle < HINSTANCE_ERROR then
    lbLoadStatus.Caption := SystemErrorMessage + ' (Error ' + IntToStr(GetLastError) + ')'
  else
    lbLoadStatus.Caption := 'DLL cargada exitosamente';

  Hola := THola(GetProcAddress(FDLLHandle, 'Hola'));

  {if procedure is found in the dll}
  if not Assigned(@Hola) then
  begin
    lbLoadStatus.caption := SystemErrorMessage + ' (Error ' + IntToStr(GetLastError) + ')'
  end
  else
  begin
    Res := Hola();
    lbLoadStatus.caption := 'Hola Retorna :' + IntToStr(res);
  end;
end;


Thanks for your answers,

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Unable to Create 64 bit DLL in Windows
« Reply #1 on: July 30, 2011, 10:20:40 pm »
Have you tryed using FPC Trunk? Which FPC versions have you tried? Changing Lazarus itself shouldn't change anything here, the important is the version of FPC.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Unable to Create 64 bit DLL in Windows
« Reply #2 on: July 31, 2011, 09:12:27 am »
Code: [Select]
--- This is the exported function

function Hola: Int64; stdcall; export;

...

---- This is the call

// Early Binding

function Hola: Int64; external 'testhola.dll';
You miss stdcall in the external declaration.

williamda

  • Newbie
  • Posts: 5
    • Visión Tecnológica
Re: Unable to Create 64 bit DLL in Windows
« Reply #3 on: August 02, 2011, 11:56:43 pm »

You´re right, I missed to put stdcall at the external definition. I fixed it, but still get the same error  (0xc000007b) when launching the application.

I also downloaded the fpc trunk, but I don´t now how to make it work with Lazarus. I´ll appreciate some advice or a link to learn how .

Thanks for your replies,

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12171
  • Debugger - SynEdit - and more
    • wiki
Re: Unable to Create 64 bit DLL in Windows
« Reply #4 on: August 03, 2011, 12:38:37 am »
1) Debugging: If you use FPC trunk; and Lazarus trunk, then it should work.
But make sure your anti-virus does not interfere.

2) On 32 bit (but may happen on 64 bit too, don't know), I had once problems with dll. Turned out that bitdefender (Antivirus) just deleted the dll file => without warning, and despite all settings, saying to *always* ask first. Maybe ?

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2673
Re: Unable to Create 64 bit DLL in Windows
« Reply #5 on: August 03, 2011, 09:21:52 am »
1) How did you declare FDLLHandle ? some handle types are still defined 32 bit on a 64bit windows.

2) (iirc) check for Assigned(Hola) instead of Assigned(@Hola)
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

 

TinyPortal © 2005-2018