From cf62104f5b68e21d07546c13fced7093e9df1ca9 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Tue, 6 Aug 2024 05:32:14 -0700 Subject: [PATCH] Get path of conpty.node for conpty.dll Part of microsoft/vscode#224488 --- src/win/conpty.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/win/conpty.cc b/src/win/conpty.cc index eeafd3c5c..9586b6c49 100644 --- a/src/win/conpty.cc +++ b/src/win/conpty.cc @@ -171,20 +171,24 @@ HANDLE LoadConptyDll(const Napi::CallbackInfo& info, return LoadLibraryExW(L"kernel32.dll", 0, 0); } wchar_t currentDir[MAX_PATH]; - DWORD result = GetCurrentDirectoryW(MAX_PATH, currentDir); + HMODULE hModule = GetModuleHandleA("conpty.node"); + if (hModule == NULL) { + throw errorWithCode(info, "Failed to get conpty.node module handle"); + } + DWORD result = GetModuleFileNameW(hModule, currentDir, MAX_PATH); if (result == 0) { - throw errorWithCode(info, "Failed to get current directory"); + throw errorWithCode(info, "Failed to get conpty.node module file name"); } - std::wstring currentDirStr(currentDir); - - std::wstring conptyDllPath = currentDirStr + L"\\build\\Release\\conpty\\conpty.dll"; + PathRemoveFileSpecW(currentDir); + wchar_t conptyDllPath[MAX_PATH]; + PathCombineW(conptyDllPath, currentDir, L"conpty\\conpty.dll"); if (!path_util::file_exists(conptyDllPath)) { - std::wstring errorMessage = L"Cannot find conpty.dll at " + conptyDllPath; - std::string errorMessageStr(errorMessage.begin(), errorMessage.end()); + std::wstring errorMessage = L"Cannot find conpty.dll at " + std::wstring(conptyDllPath); + std::string errorMessageStr = path_util::wstring_to_string(errorMessage); throw errorWithCode(info, errorMessageStr.c_str()); } - return LoadLibraryW(conptyDllPath.c_str()); + return LoadLibraryW(conptyDllPath); } HRESULT CreateNamedPipesAndPseudoConsole(const Napi::CallbackInfo& info,