Recent

Author Topic: A quick question about library and shortstrings  (Read 451 times)

cdbc

  • Hero Member
  • *****
  • Posts: 1025
    • http://www.cdbc.dk
A quick question about library and shortstrings
« on: September 24, 2022, 11:24:03 am »
Hi
Instead of using pchars in library funcrions, is it possible to use shortstrings e.g.
Code: Pascal  [Select][+][-]
  1. type
  2.   TStr80 = string[80];
  3. ...
  4.  
  5. 1) Function libGetVersion(hObj: ptruint): pchar; cdecl; // works fine
  6. 2) Function libGetVersion(hObj: ptruint): shortstring; cdecl; // ?!?
  7. 3) Function libGetVersion(hObj: ptruint): TStr80; cdecl; // ?!?
  8.  
Would 2 or 3 be ok?
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

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: A quick question about library and shortstrings
« Reply #1 on: September 24, 2022, 11:29:40 am »
1. works fine for string[255]
Anyway it is better to use Pchar, unless you know for sure the library is Pascal and you use it ONLY from Pascal.
And make sure you do not rely on Pascal's memory management.
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Re: A quick question about library and shortstrings
« Reply #2 on: September 24, 2022, 11:53:39 am »
If the other side can be made to understand it, then yes. shortstring is a normal static type like a fixed array.

shortstring without [] is equal to shortstring[255]

cdbc

  • Hero Member
  • *****
  • Posts: 1025
    • http://www.cdbc.dk
Re: A quick question about library and shortstrings
« Reply #3 on: September 24, 2022, 12:48:28 pm »
Hi
Thank you both  :)
I'm in control of both the library(*.so) and the app... I was just curious  :D
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

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Re: A quick question about library and shortstrings
« Reply #4 on: September 24, 2022, 01:24:36 pm »
Note that the problem with shortstrings is obviously the length limitation.

 

TinyPortal © 2005-2018