//\r
// This file is to be included when using Win32 capabilities in df32func.mk\r
//\r
-// Copyright (c) 2006-2009, glyn@8kb.co.uk\r
+// Copyright (c) 2006-2015, glyn@8kb.co.uk\r
// \r
// df32func/win32.inc\r
//-------------------------------------------------------------------------\r
move (trim(argv)) to l_sUnicode\r
\r
if (l_sUnicode <> "") begin\r
- zerostring 100 to l_sAscii\r
+ zerostring (length(l_sUnicode)) to l_sAscii\r
getAddress of l_sAscii to l_pAscii\r
getAddress of l_sUnicode to l_pUnicode\r
\r
- // set the length of cchWideChar to -1 and function assumes null termination and calculates lenght itsself\r
+ // set the length of cchWideChar to -1 and function assumes null termination and calculates length itsself\r
move (WideCharToMultiByte(CP_OEMCP,0,l_pUnicode,-1,0,0,0,0)) to l_iCharsNeeded \r
move (WideCharToMultiByte(CP_OEMCP,0,l_pUnicode,-1,l_pAscii,l_iCharsNeeded,0,0)) to l_iThrow\r
end\r
- function_return l_sAscii\r
+ function_return (cstring(l_sAscii))\r
end_function\r
\r
// Attempt to convert a string from ASCII to unicode via MultiByteToWideChar\r
move (trim(argv)) to l_sAscii\r
\r
if (l_sAscii <> "") begin\r
- zerostring 100 to l_sUnicode\r
+ zerostring (length(l_sAscii)*2) to l_sUnicode\r
getAddress of l_sUnicode to l_pUnicode\r
getAddress of l_sAscii to l_pAscii\r
\r
- // set the length of cchWideChar to -1 and function assumes null termination and calculates lenght itsself\r
+ // set the length of cchWideChar to -1 and function assumes null termination and calculates length itsself\r
move (MultiByteToWideChar(CP_ACP,0,l_pAscii,-1,0,0,0,0)) to l_iCharsNeeded \r
move (MultiByteToWideChar(CP_ACP,0,l_pAscii,-1,l_pUnicode,l_iCharsNeeded,0,0)) to l_iThrow\r
end\r
- function_return l_sUnicode \r
+ function_return (cstring(l_sUnicode)) \r
end_function\r
\r
// Attempt to convert a string from ascii to UTF8 via WideCharToMultiByte\r
move (trim(argv)) to l_sUnicode\r
\r
if (l_sUnicode <> "") begin\r
- zerostring 100 to l_sUTF8\r
+ zerostring (length(l_sUnicode)) to l_sUTF8\r
getAddress of l_sUTF8 to l_pUTF8\r
getAddress of l_sUnicode to l_pUnicode\r
\r
move (WideCharToMultiByte(CP_UTF8,0,l_pUTF8,-1,l_pUnicode,l_iCharsNeeded,0,0)) to l_iThrow\r
end\r
\r
- function_return l_sUTF8\r
+ function_return (cstring(l_sUTF8))\r
+end_function\r
+\r
+// https://msdn.microsoft.com/en-us/library/windows/desktop/ms647473%28v=vs.85%29.aspx\r
+// Note security considerations, as this function doesn't enforce string lengths\r
+function ansi_to_oem global string argv returns string\r
+ local string l_sOem l_sAnsi\r
+ local pointer l_pOem l_pAnsi\r
+ local integer l_iResult\r
+ \r
+ if (length(argv) <> 0) begin\r
+ move argv to l_sAnsi\r
+ getaddress of l_sAnsi to l_pAnsi\r
+ zerostring (length(l_sAnsi)+1) to l_sOem\r
+ getaddress of l_sOem to l_pOem\r
+ move (CharToOem(l_pAnsi, l_pOem)) to l_iResult\r
+ end\r
+ else;\r
+ move argv to l_sOem\r
+ \r
+ function_return (cstring(l_sOem))\r
+end_function\r
+\r
+// https://msdn.microsoft.com/en-us/library/windows/desktop/ms647493%28v=vs.85%29.aspx\r
+// Note security considerations, as this function doesn't enforce string lengths\r
+function oem_to_ansi global string argv returns string\r
+ local string l_sOem l_sAnsi\r
+ local pointer l_pOem l_pAnsi\r
+ local integer l_iResult\r
+ \r
+ if (length(argv) <> 0) begin\r
+ move argv to l_sOem\r
+ getaddress of l_sOem to l_pOem\r
+ zerostring (length(l_sOem)+1) to l_sAnsi\r
+ getaddress of l_sAnsi to l_pAnsi\r
+ move (CharToOem(l_pOem, l_pAnsi)) to l_iResult\r
+ end\r
+ else;\r
+ move argv to l_sAnsi\r
+ \r
+ function_return (cstring(l_sAnsi))\r
end_function\r
\r
// Get running processes on the system\r