View Full Version : OemTOutf16Buffer throws Illegal Datatype Conversion 4381

6-Sep-2022, 12:39 PM
Just got a message from the office and free wifi in Tampa is awful so I don't expect to be able to dig out the answer.

Point 1, though, OemToUtf16Buffer isn't in the help but OemToUtf8Buffer is.

below is updated


I keep getting illegal datatype conversion error when I run RprNightBreit2. The function that gives me the error is in the screenshot below. It is in CharTranslate.pkg.

//Converts a OEM string to UTF-16
//pOemBuf = Pointer to OEM string
//iLen = Length of OEM string in bytes
//Returns pointer to UTF-16 string, use free() to deallocate buffer when it's no longer needed
Function OemToUtf16Buffer Global Pointer pOemBuf Integer iLen Returns Pointer
Pointer pWideBuf
Integer iWideBufLen
Move 0 to pWideBuf
Move (MultiToWideBuffer(CP_OEMCP,pOemBuf,iLen,AddressOf (pWideBuf))) to iWideBufLen
If (iWideBufLen=0) Begin
Function_Return 0
Function_Return pWideBuf

called from

Function OemToUtf16String Global String sSource Integer iBlockUTF16 Returns String //Will's version
String sDestination
Address pDest pConverted
Boolean bVoid
ZeroString 2 to sDestination //was 2048
Move (AddressOf(sDestination)) to pDest
Move (OemToUtf16Buffer(AddressOf(sSource), CStringLength(sSource))) to pConverted
Move (MemCopy(pDest,pConverted,iBlockUTF16)) to bVoid //was 2048
If (not(bVoid)) Begin
Showln "failed to convert " sSource
Move (Free(pConverted)) to bVoid
Function_Return sDestination

and OEMtoUTF16String is called from the StartReport

Move 0 to icount
Direct_Input channel 8 sFile //reopen ascii workfile

ZeroString 1 to sLineIn
ZeroString 1 to sLineOut
Read_Block channel 8 sLineIn 1 //iBlockASCII
Increment iCount
If (sLIneIn<>sNUL) Begin
Move (OemToUtf16string(sLineIn, 1)) to sLineOut
Get BinaryFileWrite of oFilesystem iFile (&sLineOut) to bVoid
If (not(bVoid)) Begin
Send UserError ("Write failed at character #" *(String(icount)))
Until (sLIneIn=sEOF or sLIneIn=sNUL)


8-Sep-2022, 08:17 AM
any chance of documenting OemToUtf16Buffer?

Dennis Piccioni
8-Sep-2022, 08:29 AM
Hi Dave,

can you use Utf16FromBuffer (https://docs.dataaccess.com/dataflexhelp/mergedProjects/VDFClassRef/cCharTranslate-Function-Utf16FromBuffer.htm)?

Harm Wibier
8-Sep-2022, 08:50 AM
And can you explain what you are trying to do? Are you trying to write a file in UTF-16? Is the data really OEM? What version of DataFlex are you on?

14-Sep-2022, 03:18 PM
Wempy solved it:

//Move (OemToUtf16Buffer(AddressOf(sSource), CStringLength(sSource))) to pConverted
Move (OemToUtf16Buffer(AddressOf(sSource), CStringLength(AddressOf(sSource)))) to pConverted