Recent

Author Topic: Library made on Lazarus is throwing access violations  (Read 4579 times)

filipenf

  • Newbie
  • Posts: 5
Library made on Lazarus is throwing access violations
« on: May 09, 2005, 04:50:23 pm »
I have an application made in delphi that calls a DLL (dinamically loaded) that was also made in delphi.
But now, I rewrote that library in Lazarus and when it's code is called I get Access Violations in my application. By debuging the application I saw that the exported function is being correctly loaded by delphi's app. For example:
...
  self.lib := LoadLibrary(PChar(DLL));
  if self.lib>0 then
    @myFunc := GetProcAddress(lib,'func');
...
myFunc gets the address of that procedure in the DLL file.

Another think is that myFunc receives a record it's parameter, this record have only primitive types, cardinals, pchars, and no strings.
If in the exported function (lazarus) I don't use that record, the code executes with no errors, but if I use it I got stack overflow or access violation.
The procedure's are built with cdecl calling convention but I have already tested with stdcall and the result is the same.

Thanks for any help

Anonymous

  • Guest
Library made on Lazarus is throwing access violations
« Reply #1 on: May 10, 2005, 06:50:44 pm »
Did you used packed record  ? I don't know (yet, since I'm learning FPC) how is record packed in Lazarus but it's probably that problem.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2663
Library made on Lazarus is throwing access violations
« Reply #2 on: May 11, 2005, 12:01:31 pm »
the record packing is the same as in Delphi, so I don't expect a problem there. However what calling convention do your exported functions have ? If there is no convention given, Delphi uses its own register calling, which is probably not compatible with fpc. To avoid interfacing problems, exported functions should always have a stdcall calling.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Anonymous

  • Guest
Library made on Lazarus is throwing access violations
« Reply #3 on: May 13, 2005, 08:47:00 pm »
I used cdecl since I thought it was the best way for doing that and because I'll write other library in c and I've heard that C uses the cdecl calling convention. My record is not packed, this will work OK on c if I create a struct to store the data passed by the record?

PS: after that problems, I rewrote both the library and the program to pass all data as parameter instead of using record ( about nine parameters ) and it then worked OK. What is the preferred way to do this? passing record or primitives?

Thanks

 

TinyPortal © 2005-2018