This example shows how to convert code page encoded characters to Unicode.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <uconv.h>
int main(void) {
UconvObject  uconv_object = NULL;
int          rc = ULS_SUCCESS;
size_t       in_bytes_left;
size_t       uni_chars_left;
size_t       num_subs;
int          uni_buf_length = 50;
UniChar      uni_buffer[50];
UniChar      *pout_uni_str;
char         char_data[] = "Character string to convert";
char         *pin_char_str;

         /********************************************************************/
         /* Create a conversion object based upon the process code page      */
         /********************************************************************/

         rc = UniCreateUconvObject((UniChar *)L"", &uconv_object);

         if (rc != ULS_SUCCESS) {
           printf("UniCreateUconvObject error: return code = %u\n", rc);
           return 1;
         }
        /*********************************************************************/
        /* pin_char_str points to the character string to be converted to    */
        /* Unicode characters                                                */
        /*********************************************************************/

        pout_uni_str = uni_buffer;
        pin_char_str = char_data;

        uni_chars_left = uni_buf_length;
        in_bytes_left = ( strlen(char_data) + 1 ) * sizeof(char);
       /**********************************************************************/
       /* make call to convert code page character string to a Unicode string*/
       /**********************************************************************/

       rc = UniUconvToUcs(uconv_object, (void **)&pin_char_str, &in_bytes_left,
                         &pout_uni_str, &uni_chars_left,
                         &num_subs);

        if(rc != ULS_SUCCESS && in_bytes_left > 0) {
           printf("UniUconvToUcs error: return code = %u\n", rc);
           printf("Character string was not completely converted to Unicode\n");
           return 1;
        }
        return ULS_SUCCESS;
}


[Back: UniUconvToUcs - Related Functions]
[Next: UniUconvToUcs - Topics]