[0.9.25/Win32] Section Initialization dans une librairie Win32
Bonjour,
Une fonction de mon code produit des N° de licences aléatoires. Le randomize est déclaré en début de programme. cela fonctionne. J'ai transféré cette fonction dans une librairie (.dll) appelée par le programme. Le randomize ne fonctionne plus. Il semble que vue de la librairie, la graine du randomize soit vide. J'ai donc incorporé le randomize dans la librairie dans une section initialization. Le résultat est probant... sauf que la dll construite par lazarus n'est plus le fichier bibli.dll mais un fichier bibli.exe. En renommant bibli.exe en bibli.dll, cela fonctionne. C'est visiblement cette partie initialization qui engendre le problème...
Voici un extrait du code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| library bibli;
{$mode objfpc}{$H+}
uses
Classes,
{ you can add units after this }
SysUtils,
StrUtils;
function AleaLICENCE():Pchar;cdecl; //ou stdcall;
begin
...
end;
exports
AleaLICENCE;
//La présence de la section initialization fait générer la dll en exe ?
initialization
Randomize;
{$IFDEF WINDOWS}{$R bibli.rc}{$ENDIF}
//begin
end. |
Pour pouvoir construire sans erreur avec la section initialization, il faut commenter le begin "final".
Pour info
ppa.bat si pas {$IFDEF WINDOWS}{$R bibli.rc}{$ENDIF}
Citation:
@echo off
d:\lazarus0925\fpc\2.2.3\bin\i386-win32\windres.exe --include d:\lazarus0925\fpc\2.2.3\bin\i386-win32\ -O res -o sdsql.res sdsql.rc --preprocessor=d:\lazarus0925\fpc\2.2.3\bin\i386-win32\cpp.exe
if errorlevel 1 goto linkend
SET THEFILE=bibli.exe
echo Linking %THEFILE%
d:\lazarus0925\fpc\2.2.3\bin\i386-win32\ld.exe -b pe-i386 -m i386pe --gc-sections -s --dll --entry _DLLMainCRTStartup --base-file base.$$$ -o bibli.exe link.res
if errorlevel 1 goto linkend
d:\lazarus0925\fpc\2.2.3\bin\i386-win32\dlltool.exe -S d:\lazarus0925\fpc\2.2.3\bin\i386-win32\as.exe -D bibli.exe -e exp.$$$ --base-file base.$$$
if errorlevel 1 goto linkend
d:\lazarus0925\fpc\2.2.3\bin\i386-win32\ld.exe -b pe-i386 -m i386pe -s --dll --entry _DLLMainCRTStartup -o bibli.exe link.res exp.$$$
if errorlevel 1 goto linkend
d:\lazarus0925\fpc\2.2.3\bin\i386-win32\postw32.exe --subsystem console --input bibli.exe --stack 16777216
if errorlevel 1 goto linkend
goto end
:asmend
echo An error occured while assembling %THEFILE%
goto end
:linkend
echo An error occured while linking %THEFILE%
:end
J'ai lu dans la liste des bugs qu'à un moment, cette section initialization n'était pas prise en compte sous linux
http://bugs.freepascal.org/view.php?id=9089
mais rien de particulier n'est signalé sous windows...
Il y a-t-il une astuce qui m'échappe ?
Lazarus 0.9.25 Win32.