Results 1 to 5 of 5

Thread: OemTOutf16Buffer throws Illegal Datatype Conversion 4381

  1. #1
    Join Date
    Feb 2009
    Location
    Cayman Islands
    Posts
    3,969

    Default OemTOutf16Buffer throws Illegal Datatype Conversion 4381

    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

    ...
    Dave,

    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.

    Code:
    //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
        End
        Function_Return pWideBuf
    End_Function
    called from

    Code:
        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
         End
         Move (Free(pConverted)) to bVoid
         Function_Return sDestination
        End_Function
    and OEMtoUTF16String is called from the StartReport

    Code:
            Move 0 to icount
            Direct_Input channel 8 sFile //reopen ascii workfile
     
            Repeat
                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)))
                        Procedure_Return
                    End
                End
            Until (sLIneIn=sEOF or sLIneIn=sNUL)
    D
    Last edited by DaveR; 7-Sep-2022 at 08:00 AM.
    I should be on a beach ...

  2. #2
    Join Date
    Feb 2009
    Location
    Cayman Islands
    Posts
    3,969

    Default Re: OemTOutf16Buffer throws Illegal Datatype Conversion 4381

    any chance of documenting OemToUtf16Buffer?
    I should be on a beach ...

  3. #3
    Join Date
    Nov 2008
    Location
    Round Rock, TX
    Posts
    8,850

    Default Re: OemTOutf16Buffer throws Illegal Datatype Conversion 4381

    Hi Dave,

    can you use Utf16FromBuffer?

  4. #4
    Join Date
    Feb 2009
    Location
    The Netherlands
    Posts
    4,674

    Default Re: OemTOutf16Buffer throws Illegal Datatype Conversion 4381

    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?

  5. #5
    Join Date
    Feb 2009
    Location
    Cayman Islands
    Posts
    3,969

    Default Re: OemTOutf16Buffer throws Illegal Datatype Conversion 4381

    Wempy solved it:


    //Move (OemToUtf16Buffer(AddressOf(sSource), CStringLength(sSource))) to pConverted
    Move (OemToUtf16Buffer(AddressOf(sSource), CStringLength(AddressOf(sSource)))) to pConverted
    I should be on a beach ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •