Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-06

Using AnsiString/WideString with C Library

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Hello.

I'm writing a wrapper for a C library that allows the use of UNICODE. I did wrappers for C libraries but using only ASCII strings. I did:

UNIT example;
INTERFACE
PROCEDURE Proc (Text: ANSISTRING);
IMPLEMENTATION
  { Wrapper for the C function. }
  PROCEDURE _C_Proc_ (Text: PCHAR); CDECL; EXTERNAL 'lib.dll' NAME 'proc';
PROCEDURE Proc (Text: ANSISTRING);
BEGIN
  _C_Proc (PCHAR (Text));
END;
END.

This way I can use Pascal strings with C functions.

I've read the documentation and I find that I can use WIDESTRING in a similar way, but I'm not sure which character codification WIDESTRING uses. The C library uses 'standard C strings' (that is 'char *string;') an there's a function to define the character codification to be used by the library. It's possible to use ASCII, UTF-8, UTF-16 and UTF-32.

Can WIDESTRING use all UNICODE codifications and ASCII strings?

If it can't, is there a way to use UNICODE strings?

Thanks in advance.

Guillermo Martínez Jiménez

[p.s.] Por cierto, escribo tonterías y hago budujos que podéis ver y leer aquí --> http://dibujantemomar.deviantart.com/ y aquí --> http://dibujantemomar.spaces.live.com/

Marco van de Voort
to Unknown author
This way I can use Pascal strings with C functions. I've read the documentation and I find that I can use WIDESTRING in a similar way, but I'm not sure which character codification WIDESTRING uses

UCS2 which is a subset (more like a draft for) of UTF16. Maybe Microsoft has fixed this to be fully UTF16 compliant in XP+ though.

Show quoted text 5 lines
The C library uses 'standard C strings' (that is 'char *string;') an there's a function to define the character codification to be used by the library. It's possible to use ASCII, UTF-8, UTF-16 and UTF-32. Can WIDESTRING use all UNICODE codifications and ASCII strings?

If there are differences, they revolve around the differences between UCS2 and UTF16. (surrogate pairs mostly, maybe endianess support)

If it can't, is there a way to use UNICODE strings?

There is no such thing. There are multiple unicode encodings (UTF-*, UCS-* etc)

Daniël Mantione
to Unknown author: Hello. I'm writing a wrapper for a C library that allows the use of UNICODE. I did…

Op Mon, 4 Jun 2007, schreef

Show quoted text 7 lines
I've read the documentation and I find that I can use WIDESTRING in a similar way, but I'm not sure which character codification WIDESTRING uses. The C library uses 'standard C strings' (that is 'char *string;') an there's a function to define the character codification to be used by the library. It's possible to use ASCII, UTF-8, UTF-16 and UTF-32. Can WIDESTRING use all UNICODE codifications and ASCII strings?

An ansistring uses 8 bit characters, while a widestring uses 16-bit characters. A widestring is normally UCS-2 or UTF-16 encoded.

Assignments to and from ansistrings convert to and from the system code page, i.e. if the system uses an ISO-8859-1 encoding, converting ansistrings from/to widestring converts to/from ISO-8859-1. Further, there is utfencode and utf8decode, which convert an utf-8 encoded ansistring to/from a widestring.

Daniël