Sign in Join
Wiki copytemporary

DLL dynamically load/ru

Deutsch · English · Русский · 中文(中国)

В руководстве показано, как динамически загружается DLL (библиотека динамической компоновки).

Библиотека DLL (DLLTest.dll), указанная в примере ниже:

pascal
 library info;

 {$mode objfpc} {$H+}

 uses
   SysUtils;

 {$R *.res}

 // Подпрограмма DLL
 function funStringBack(strIn : string) : PChar;
   begin
     funStringBack := PChar(UpperCase(strIn));
   end ;

 // Экспортированная подпрограмма(ы)
 exports
   funStringBack;

 begin
 end.

Что я должен делать:

Интегрируйте, используйте и выпустите подпрограмму DLL в вашей собственной программе:

pascal
 uses
   Windows, ...;

   ...

 Include function funDll : string;
 type
   // Определение вызываемой подпрограммы, как задано в DLL, которая будет использоваться
   TfunStringBack = function(strIn : string) : PChar;  stdcall;

 var
   // Создаем подходящую переменную (поле данных) для подпрограммы DLL
   funStringBack : TfunStringBack;
   // Создаем дескриптор для DLL
   LibHandle : THandle;

 begin
   // Получаем дескриптор библиотеки, которая будет использоваться
   LibHandle := LoadLibrary(PChar('DLLTest.dll'));

   // Проверяем успешность загрузки DLL
   if LibHandle <> 0 then
     begin
       // Назначаем адрес вызова подпрограммы переменной funStringBack
       // 'funStringBack' из DLL DLLTest.dll
       Pointer(funStringBack) := GetProcAddress(LibHandle, 'funStringBack');

       // Проверяет, был ли возвращен действительный адрес
       if @funStringBack <> nil then
         Result := funStringBack('hello world');
     end;

   // освобождаем память
   funStringBack := nil;
   FreeLibrary(LibHandle);

 end;

   ...

From the Free Pascal wiki, page "DLL dynamically load/ru", as it stood on 2020-12-15 after a change by Zoltanleo, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Edited on wiki.freepascal.org by 1 person, 2020

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
ZoltanleoCreated page
Zoltanleo

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.