Recent

Author Topic: [SOLVED] FreePascal book covering only DLLs...  (Read 4087 times)

GypsyPrince

  • New Member
  • *
  • Posts: 35
Re: FreePascal book covering only DLLs...
« Reply #15 on: November 21, 2020, 11:30:54 pm »
Out of the numerous Pascal affilated books I've purchased here in the last month,  'Sam's Teach Yourself Borland Delphi 4' and the 'Borland Delphi 6 Developer's Guide' used together seem to offer the broadest and most thorough, yet most down-to-earth laymen explanation on DLLs in OP.

https://www.amazon.com/Sams-Teach-Yourself-Delphi-Days/dp/0672312867

https://www.amazon.com/Delphi-Developers-Guide-Sams-Guides/dp/0672321157/ref=sr_1_3?dchild=1&keywords=Delphi+Developer%27s+guide&qid=1605997766&sr=8-3

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: FreePascal book covering only DLLs...
« Reply #16 on: November 22, 2020, 12:57:22 pm »
In both .NET and Java, when you create an object from (link to or load) a DLL written in one of those managed languages, you are actually creating a new instance of a class within the DLL, rather than creating an instance of the DLL itself. Why? Because in such cases it is handled by the managed platform (.NET/Java) rather than by the OS. In reality, though, it is the managed platform by which the program communicates with the operating system, which subsequently handles the library. However, when writing a .NET/Java application which loads a DLL created in some other language such as a C/C++ based DLL, then you do create an instance of the actual DLL itself, because there is no managed platform acting as a virtual machine liason between the program and the operating system. Therefore, the library is handled immediatley by the OS without a managed platform/virtual machine (and classes) acting as an intermediary.

You are mixing loading of the library and the data state here. First of Java does not know libraries (at least not in this sense) and if it uses precompiled libraries though JNI or such it uses the same mechanisms as any C or Pascal program would. And for .NET libraries the same holds true as for a library written in C or Pascal: if the program loads a library the operating system maps the library into the applications virtual memory and then it can call there as it sees fit. No data state is shared between different “instances” by default (while the code is shared).

So assume you have the following code:

Code: Pascal  [Select][+][-]
  1. library Test;
  2.  
  3. {$mode objfpc}
  4.  
  5. var
  6.   i: LongInt = 0;
  7.  
  8. function GetValue: LongInt; stdcall;
  9. begin
  10.   if i = 0 then begin
  11.     Randomize;
  12.     i := Random(High(LongInt) - 1) + 1;
  13.   end;
  14.   Result := i;
  15. end;
  16.  
  17. exports
  18.   GetValue;
  19.  
  20. begin
  21. end.

Then you'll get a different number when calling GetValue for each run of the program no matter if your program is written in Java, C#, Free Pascal or whatever.

Also an important point that I had already mentioned earlier: You do not pass classes or other Pascal types like AnsiString or such across library boundaries. This will only lead to problems rather sooner than later. The only safe ones are primitive types, records, pointers (though these need to be freed by whoever allocated them or you need to pass the memory manager along as well) and interfaces (especially the COM ones where designed for this). On Windows you can also pass WideString, because it uses operating system functionality.

Passing classes and such around will only work once dynamic packages are supported, but these are not ready for prime time yet.

GypsyPrince

  • New Member
  • *
  • Posts: 35
Re: [SOLVED] FreePascal book covering only DLLs...
« Reply #17 on: November 22, 2020, 06:34:45 pm »
Okay, this is getting way out of range from what I'm talking about and doesn't reflect what I'm saying. From the beginning there seems to be a complete misinterpretation or a loss in translation, so I'm just going to say here that I got the information I needed and finished my DLL - it works perfectly.
 
All is good.


@cdbc
Thank you for grasping what I was asking! Your examples were invaluable!!!

cdbc

  • Hero Member
  • *****
  • Posts: 1079
    • http://www.cdbc.dk
Re: [SOLVED] FreePascal book covering only DLLs...
« Reply #18 on: November 23, 2020, 03:33:39 pm »
No worries mate, I'm glad you got it to work  :)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: [SOLVED] FreePascal book covering only DLLs...
« Reply #19 on: November 23, 2020, 04:33:25 pm »
Okay, this is getting way out of range from what I'm talking about and doesn't reflect what I'm saying. From the beginning there seems to be a complete misinterpretation or a loss in translation, so I'm just going to say here that I got the information I needed and finished my DLL - it works perfectly.

It's getting out of hand, because you either have a wrong concept of how libraries work or because there's a language barrier in the way.

GypsyPrince

  • New Member
  • *
  • Posts: 35
Re: [SOLVED] FreePascal book covering only DLLs...
« Reply #20 on: November 23, 2020, 06:41:59 pm »
Quote
It's getting out of hand, because you either have a wrong concept of how libraries work

I have a very good concept of how libraries work, as I've been programming in various languages since 1984. cdbc knew exactly was I was asking and provided the material I needed, so I can only assume that the issue must be a language barrier.

 

TinyPortal © 2005-2018