Search code examples
lotus-noteslotus

OS_TRANSLATE_LMBCS_TO_UNICODE Issue


I am using OSTranslate to convert my mail body content to Unicode String. Which is working fine for char* less then WORD size 65535.

WORD Length = MAXWORD;
actualOutLength = OSTranslate(OS_TRANSLATE_LMBCS_TO_UNICODE, (char*)inPtr,
Length, (char*)outPtr, Length);

After conversion the output array contains only a part of a source string.

Please Suggest what is the correct approach to set the size as my input string size is exceeding MAXWORD size limit.


Solution

  • One way I've come up with is that if (MAXWORD-actualOutLength<4) then take the output buffer and do the reverse translate using OS_TRANSLATE_UNICODE_TO_LMBCS. You will throw away this result -- but the length returned is the length of the portion of your original input buffer that was processed. So you can use that length to advance your inPtr, call OSTranslate again with OS_TRANSLATE_LMBCS_TO_UNICODE again and continue building your extended output buffer in a loop until you exhaust your input buffer. Note that this would only work if your input string is LMBCS optimized for Group 1. If it was optimized for a different group, the reverse translation length will probably not align with the characters in your input buffer.

    Another way would be to use NLS_get in a loop to count out characters in the input buffer up to MAXWORD/2. You can then use either NLS_translate or OSTranslate on a the first part of the input buffer and be sure that the output will fit within MAXWORD. Then start counting again from the last pointer you received back from NLS_get, and continue in a loop until you have run through the entire input buffer.