Recent

Author Topic: [CLOSED] LoadLibrary() in initialization section  (Read 431 times)

julkas

  • Hero Member
  • *****
  • Posts: 630
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
[CLOSED] LoadLibrary() in initialization section
« on: July 04, 2020, 06:10:21 pm »
Is it safe call LoadLibrary() from unit initialization section?
Thanks.
« Last Edit: July 05, 2020, 06:55:59 pm by julkas »
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

jamie

  • Hero Member
  • *****
  • Posts: 3277
Re: LoadLibrary() in initialization section
« Reply #1 on: July 04, 2020, 10:16:07 pm »
Yes, in fact its most likely the best place since that gets called before any of the code does in the units.

Those sections get called first before the first line of your main file gets executed.
The only true wisdom is knowing you know nothing

Cyrax

  • Hero Member
  • *****
  • Posts: 830
Re: LoadLibrary() in initialization section
« Reply #2 on: July 05, 2020, 11:00:36 am »
It is if your application is an executable, not dynamic loadable library. Windows OS  will add some restrictions on this : https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices

Under Unix OS (at least Linux), it seems that you can use it as you fit without any restrictions.

julkas

  • Hero Member
  • *****
  • Posts: 630
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
Re: LoadLibrary() in initialization section
« Reply #3 on: July 05, 2020, 06:55:00 pm »
Thanks.
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

 

TinyPortal © 2005-2018