WSGetUTF16String (C Function)

int WSGetUTF16String(WSLINK link,const unsigned short **s,int *n,int *c)

gets a UTF-16 character string from the WSTP connection specified by link, storing the string in s, the length of the string in n, and the number of characters in c.

Details

  • WSGetUTF16String() allocates memory for the character string. You must call WSReleaseUTF16String() to disown this memory. If WSGetUTF16String() fails and the function's return value indicates an error, do not call WSReleaseUTF16String() on the contents of s.
  • WSGetUTF16String() returns immutable data.
  • WSGetUTF16String() stores all characters directly in the UTF-16 Unicode encoding form.
  • The string s returned by WSGetUTF16String() begins with a byte order mark.
  • The length of the string n includes the byte order mark.
  • WSGetUTF16String() returns 0 in the event of an error, and a nonzero value if the function succeeds.
  • Use WSError() to retrieve the error code if WSGetUTF16String() fails.
  • WSGetUTF16String() is declared in the WSTP header file wstp.h.

Examples

Basic Examples  (1)

#include "wstp.h"

/* read a UTF-16 encoded string from a link */

void f(WSLINK lp)
{
    const unsigned short *string;
    int length;
    int characters;

    if(! WSGetUTF16String(lp, &string, &length, &characters))
        {
            /* unable to read the UTF-16 string from lp */
            return;
        }

    /* ... */

    WSReleaseUTF16String(lp, string, length);
}