Hello Karl,
Somewhere in my program I am using this function, no idea where I got it from:
Code: Select all
FUNCTION ConvertFromCodePageToCodePage(cString AS STRING, dwFrom AS DWORD, dwTo AS DWORD) AS STRING
LOCAL pUStr AS PTR
LOCAL pBuffer AS PTR
LOCAL nLen,nULen AS LONG
// Convert VO string from dynamic memory to fixed memory
nLen := LONG(SLen(cString))
pBuffer := MemAlloc(DWORD(nLen))
MemCopyString(pBuffer,cString,DWORD(nLen))
// Determine length of Unicode string
// And allocate enough space to hold it
nULen := MultiByteToWideChar(dwFrom,0,pBuffer,nLen,NULL_PTR, 0)
pUStr := SysAllocStringLen(NULL_PTR,DWORD(nULen))
// Convert Fixed memory Ansi string to Fixed memory Unicode string
MultiByteToWideChar(dwFrom,0,pBuffer,nLen,pUStr,nULen)
// Now determine size needed for ANSI string
nLen := WideCharToMultiByte(dwTo,0,pUStr,nULen,NULL_PTR,0, NULL,NULL)
// Allocate Fixed memory buffer to hold the UTF8 string
pBuffer := MemRealloc(pBuffer, DWORD(nLen+1))
// Convert Unicode to Ansi
nLen := WideCharToMultiByte(dwTo,0,pUStr,nULen,pBuffer,nLen ,NULL,NULL)
// Convert fixed memory buffer to dynamic memory string
cString := Mem2String(pBuffer,DWORD(nLen))
// Release fixed memory buffer
MemFree(pBuffer)
// Release the Unicode String
SysFreeString(pUStr)
RETURN cString
This calls MultiByteToWideChar which is documented here:
https://docs.microsoft.com/en-us/window ... towidechar
An example is this:
Code: Select all
cResult := ConvertFromCodePageToCodePage(SubStr2(cResult, 4), CP_UTF8, CP_ACP)
and the dwFrom and dwTo constants like CP_AP or CP_UTF8 are explained in the above page.
I hope this helps you.
Dick