[fpc-pascal] dll with windows impossible???
Michel Meunier
michel.meunier100 at wanadoo.Fr
Wed Jan 24 22:11:58 CET 2007
Hello,
I am trying again without any hope, to use dll in a wondows application.
It's very strange it's working with console application but not with
windows apllication.
My dll code is very very simple:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
library dlltest;
{$mode objfpc}{$H+}
uses
Classes
{ add your units here };
function test ( ) : integer ; stdcall ;
begin
test:=1;
end ;
exports
test ;
end .
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
next the console program wich is working, very simple:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
program testdll;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes,dynlibs
{ add your units here };
var handledll:integer;
begin
handledll:=loadlibrary('dlltest.dll');
if handledll=0 then writeln('raté') else writeln('OK');
writeln(handledll);
end.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
now the windows program:
main part:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
program testdllwindows;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms
{ add your units here }, testdllwin;
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
and the unit:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
unit testdllwin;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
Buttons,dynlibs;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var handledll:integer;
begin
handledll:=loadlibrary('dlltest.dll');
if handledll=0 then showmessage('raté') else showmessage('OK');
end;
initialization
{$I testdllwin.lrs}
end.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
and IT DOESN'T WORK, why? It is exactly the same code!
More and more I think I am going to translate my code in C, because FPC
seems unable to manage properly dll library.
Thanks for your help.
Michel
--
Michel Meunier
Web: www.etoiles-a-bleau.fr
More information about the fpc-pascal
mailing list