Simple dll function lazarus / 13-General ---------------------------------------------------------------------- ChrisX · 2006-10-13 04:23 I have been trying for a while now to get this to work. But, no luck. I have a simple dll and Lazarus project. The project should pass a string to the dll function and then the function should reply if it matchs or if it does not match how many chars are in the string. The dll is not getting the string. dll header file: Code: [Select]#define EXPORT __declspec(dllexport) EXPORT int __stdcall TestCall(char *result_996); dll c file: Code: [Select]#include #include "Tester.h" EXPORT int __stdcall TestCall(char *result_996) { (result_996 == "BOB")    {    return 1;    } else    {    return strlen(result_996);    } } Lazarus project code: Code: [Select] unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,   Buttons; type   { TForm1 }   TForm1 = class(TForm)     Button1: TButton;     Edit1: TEdit;     procedure Button1Click(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1;     function TestCall(testit:string):integer; external 'Tester.dll'; implementation { TForm1 } procedure TForm1.Button1Click(Sender: TObject); var rety:integer; result_996:string; begin result_996 := 'bobby'; rety := TestCall(result_996); Edit1.Text := inttostr(rety); end; initialization   {$I unit1.lrs} end.   The dll works fine with VB6. But it is failing at the strlen() when called from Lazarus. Any help would be appreciated. ---------------------------------------------------------------------- Vincent Snijders · 2006-10-13 06:57 Try this: Code: [Select]function TestCall(testit:pchar):integer; external 'Tester.dll'; and Code: [Select]rety := TestCall(pchar(result_996)); ---------------------------------------------------------------------- ChrisX · 2006-10-13 14:10 Same error ---------------------------------------------------------------------- Vincent Snijders · 2006-10-13 14:26 Another correction: Code: [Select]function TestCall(testit:pchar):integer; external 'Tester.dll'; stdcall; ---------------------------------------------------------------------- theo · 2006-10-13 14:26 I'm not sure but this stuff in most cases is because of a wrong calling convention. Shouldn't it be something like:   function TestCall(testit:string):integer; stdcall; external 'Tester.dll'; ---------------------------------------------------------------------- Vincent Snijders · 2006-10-13 14:28 theo, I agree. :-) ---------------------------------------------------------------------- theo · 2006-10-13 14:29 Hmm, Vincent you win by a few seconds ;-) ---------------------------------------------------------------------- ChrisX · 2006-10-13 14:32 Quote from: "Vincent"Another correction: Code: [Select]function TestCall(testit:pchar):integer; external 'Tester.dll'; stdcall; Unit1.pas(29,67) Error: Procedure directive "STDCALL" has conflicts with other directives BUT Code: [Select]function TestCall(testit:pchar):integer; stdcall; external 'Tester.dll'; Works perfectly! THANK YOU for the help! ---------------------------------------------------------------------- Vincent Snijders · 2006-10-13 14:35 theo, but you were right. ---------------------------------------------------------------------- theo · 2006-10-13 14:39 Quote from: "Vincent"theo, but you were right. Isn't there an emoticon for "I'm an nerd" ? :-) ---------------------------------------------------------------------- matthijs · 2006-10-15 12:00 Quote from: "theo"Isn't there an emoticon for "I'm an nerd" ? :-)  :shock: Totally off topic But maybe this one will do? ---------------------------------------------------------------------- ChrisX · 2006-10-26 20:58 Another problem On Linux: Same DLL (modified to compile and named Tester.so) Same code (changed to match the renamed dll) Compile with Lazarus fails everytime with: /usr/bin/ld: cannot find -lTester I set the Projects>Compiler options> -l path to where the .so is located..no good. I copied the .so file into /usr/lib folder...no good I copied the .so file into /lib folder...no good I have copied the stupid .so file into almost every folder I have and still.....no good. Anyone have a clue what I am missing? ---------------------------------------------------------------------- Almindor · 2006-10-26 21:12 Case sensitivness perhaps? Try renaming the so to Tester.so, or change the linkname to 'tester.so'. You can use LD_LIBRARY_PATH enviro or pass -L to linker to enable additional link search paths. ---------------------------------------------------------------------- ChrisX · 2006-10-26 22:05 Quote from: "Almindor2"Case sensitivness perhaps? Try renaming the so to Tester.so, or change the linkname to 'tester.so'. You can use LD_LIBRARY_PATH enviro or pass -L to linker to enable additional link search paths. Case sensitive I thought about before and experimented with...no good. But I renamed it lowercase and tried again...no good. just tried LD_LIBRARY_PATH ...no good. -l to the linker gives the error: /usr/bin/ld: cannot find -l/usr/lib/tester.so The file is there...why does it say it cannot find it? ---------------------------------------------------------------------- ChrisX · 2006-10-28 15:48 On linux, libraries should always start with lib? I add lib to the Tester.so to make libTester.so and it works. Some things learned will stay with a person forever