Recent

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

cdbc

  • Sr. Member
  • ****
  • Posts: 401
    • 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 ;)

Thaddy

  • Hero Member
  • *****
  • Posts: 12210
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.
Manuals, manuals, manuals first.
You have incompetence and sheer incompetence.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 10404
  • 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

  • Sr. Member
  • ****
  • Posts: 401
    • 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 ;)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 10404
  • 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