Forum > General
Help me with create .dll and .so
xinyiman:
Suppose I have a dll in the same folder as the software, called miadll.dll and which contains the procedure MiaProcedura (PtrMiaLista MiaLista *);
Correctly filled with dev-cpp. As I recall from lazarus?
xinyiman:
Then the dll that I wrote with Devcpp function is declared as follows:
EXTERN_C __declspec(dllexport) VOID GetListaDSN (PtrListaODBC * MiaLista);
Instead PtrListaODBC is declared:
typedef struct ListaODBC
{
char dsn[256];
char desc[256];
struct ListaODBC * next;
}PtrListaODBC;
In my example below I tried to interact with lazarus dll. No crashes when I run, but I do not return the result I expect! How do I change it?
unit Unit1;
{$mode objfpc}{$H+}
{$ifdef unix}
{$linklib myfunc}
{$endif}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
ExtCtrls, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
type
PtrListaODBC = record
dsn : PChar;
desc : PChar;
next: integer;
end;
var
Form1: TForm1;
function GetListaDSN(MiaLista: PtrListaODBC): PChar; cdecl; external {$ifdef windows} 'ProgettoDLLODBC.dll'{$endif};
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
app: PtrListaODBC;
begin
GetListaDSN(app);
Edit1.Text:=app.dsn;
end;
initialization
{$I unit1.lrs}
end.
xinyiman:
I changed the source but now crashes when I try to exploit the variable valore with the DSN list! :o :o
unit Unit1;
{$mode objfpc}{$H+}
{$ifdef unix}
{$linklib myfunc}
{$endif}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
ExtCtrls, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
PtrListaODBC=^appoggio;
Appoggio = record
dsn : PChar;
desc : PChar;
next: PtrListaODBC;
end;
var
Form1: TForm1;
function GetListaDSN(MiaLista: PtrListaODBC): PChar; cdecl; external {$ifdef windows} 'ProgettoDLLODBC.dll'{$endif};
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
app: PtrListaODBC;
i: integer;
valore: PChar;
begin
app:=new (PtrListaODBC);
GetListaDSN(app);
i:=0;
while (app<>nil) do
begin
valore:=app^.dsn;
app:=app^.next;
end;
end;
initialization
{$I unit1.lrs}
end.
theo:
In this case, it's not PChar.
h2pas translates:
ListaODBC = record
dsn : array[0..255] of char;
desc : array[0..255] of char;
next : ^ListaODBC;
end;
PtrListaODBC = ListaODBC;
Use h2pas for header translation. Probaby it's stdcall instead of cdecl, I don't know.
captian jaster:
You can make pascal and C work together?
Navigation
[0] Message Index
[#] Next page
[*] Previous page