Skip to content

Commit

Permalink
Fixed implementation of VariableDeclarationExpression::loadNativeFunc…
Browse files Browse the repository at this point in the history
…tion() for Windows target.
  • Loading branch information
nthnn committed Dec 13, 2024
1 parent 2ef1569 commit 8ac169e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/n8/ast/expression/VariableDeclarationExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PWSTR>(
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());

Expand Down

0 comments on commit 8ac169e

Please sign in to comment.