I fixed the issue by attempting to convert UTF-8 to UTF-16 first in the C++ code, then compiling DLL and use this in Autohotkey v2:
This should be just a workaround because for some reason, the output from DllCall can only be displayed as UTF-16 (with param Cdecl Wstr)
Using UTF-8 with AStr throws an exception of Invalid memory read/write or wrong charset
The C++ code:
CODE:
output := DllCall("libs\functions.dll\displayHello", "Cdecl wStr")
OutputDebug("DllCall Output, now it is correct: " output)
CODE:
DllCall Output, now it is correct: á à ả ì í
This should be just a workaround because for some reason, the output from DllCall can only be displayed as UTF-16 (with param Cdecl Wstr)
Using UTF-8 with AStr throws an exception of Invalid memory read/write or wrong charset
The C++ code:
CODE:
#include <Windows.h>
extern "C"
{
__declspec(dllexport) const wchar_t *displayHello()
{
const char *originalString = "á à ả ì í";
// convert to utf16 before calling DLL from AHK
int requiredBufferSize = MultiByteToWideChar(CP_UTF8, 0, originalString, -1, NULL, 0);
wchar_t *utf16String = new wchar_t[requiredBufferSize];
MultiByteToWideChar(CP_UTF8, 0, originalString, -1, utf16String, requiredBufferSize);
return utf16String;
}
}
Statistics: Posted by hoangthi — Today, 11:19