Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2002-11

Error Delphi load DLL, when DLL created in FPC

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Zbigniew Kuczbański

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.

----------------------------------------------

Reply by email

Jean-Pierre Vial
to Zbigniew Kuczbański
Zbigniew Kuczbański wrote 69 lines
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

Reply by email

Maxim Artemev
to Jean-Pierre Vial
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)

Instead of *NIX :)

try something like a file creation as test instead of just writeln
or using ShowMessage();

Reply by email

Michail A.Baikov
to Maxim Artemev

We use handle's translation from main program to DLL :) Is very easy.

Show quoted text 17 lines
> > 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) Instead of *NIX :) > try something like a file creation as test instead of > just writeln or using ShowMessage(); _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel
The Linderdaum Team Audio Developing, Programmer http://www.gamedot.net

Reply by email