From 8ac169e5d8dd2c0f55246645819a93cb33c406cf Mon Sep 17 00:00:00 2001 From: Nathanne Isip Date: Fri, 13 Dec 2024 19:01:25 +0800 Subject: [PATCH] Fixed implementation of VariableDeclarationExpression::loadNativeFunction() for Windows target. --- .../VariableDeclarationExpression.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/n8/ast/expression/VariableDeclarationExpression.cpp b/src/n8/ast/expression/VariableDeclarationExpression.cpp index 14ac899..ac95dc1 100644 --- a/src/n8/ast/expression/VariableDeclarationExpression.cpp +++ b/src/n8/ast/expression/VariableDeclarationExpression.cpp @@ -91,17 +91,20 @@ NativeFunction VariableDeclarationExpression::loadNativeFunction( std::filesystem::path parentFolder = path.parent_path(); std::string parentPathFolder = parentFolder.string(); - std::wstring wstr(parentPathFolder.begin(), parentPathFolder.end()); - - PWSTR searchPath = static_cast( - CoTaskMemAlloc((wstr.size() + 1) * sizeof(wchar_t)) - ); + const char* parentPathStr = parentPathFolder.c_str(); + PWSTR searchPath = new wchar_t[MultiByteToWideChar( + CP_UTF8, 0, parentPathStr, -1, NULL, 0 + )]; if(searchPath) - wcscpy_s(searchPath, wstr.size() + 1, wstr.c_str()); + MultiByteToWideChar( + CP_UTF8, 0, + parentPathStr, + -1, pwstr, size + ); AddDllDirectory(searchPath); - CoTaskMemFree(searchPath); + delete[] searchPath; handle = LoadLibraryA(library.c_str());