[fpc-devel]Error Delphi load DLL, when DLL created in FPC

Jean-Pierre Vial jean-pierre.vial at wanadoo.fr
Wed Nov 20 21:34:55 CET 2002


Le Mercredi 20 Novembre 2002 16:34, Zbigniew Kuczbański a écrit :
> Hi,
>   I have problem when I create DLL in FPC. (FPC 1.06 Win32)
>   1.When create DLL in FPC and use it in program written in FPC - it works
> OK.
>   2. The same DLL (created in FPC) and use in Delphi (6.0) - Delphi report
> error when loading DLL.
>       Error occurs in function  LoadLibrary.
>    When in Delphi I add keyword {$APPTYPE CONSOLE} , Delphi loads my_dll
> correctly.
>    Of course, I need window application.
>
> What I can do, to write DLL in FPC and use it in Delphi.
> It's very strange for me, because both use teh same function to Load DLL ->
> LoadLibrary!
>
> Best regards
>     Zb. Kuczbanski
>
>
> Here sample code my_dll.
> ----------------------------------------------
> Library my_dll;
> Begin
>    WriteLn('Loaded DLL1');
> End.
> ----------------------------------------------
> And application written in Delphi.
> ----------------------------------------------
> program test_dll;
> uses Windows;
>
> const FarPROC : TFARPROC = nil;
>     hLib    : THandle  = 0;
> const DLLName = 'my_dll.dll';
>
>
> Function MyLoadDLL:Word;
> var Code : word;
>     w : longword;
> Begin
>   Code := 0;
>   try
>     hLib := LoadLibrary( DLLNAME );
>     if (hLib < 32) then
>     Begin
>       FarProc := NIL;
>       w := GetLastError;
>       writeln( 'Error loading librrary ', DLLName, '  error nr = ', w);
>       Code := $FFFF;
>       Exit;
>     end;
>   finally
>     MyLoadDLL := Code;
>   end;
> end;
>
> begin
>   if MyLoadDLL = 0 then
>   begin
>     writeln('Load ok.');
>   end else writeln('Load error');
>   Writeln('Press ENTER');
>   Readln;
> end.
>
> ----------------------------------------------
>
>
> _______________________________________________

the writeln procedure, without file argument,  is specifically a console 
procedure; you cannot use it in graphic mode without first creating
explicitely a standard output (that is not very easy)
try something like a file creation as test instead of 
just writeln 

-- 
Jean-Pierre Vial




More information about the fpc-devel mailing list