diff --git a/winml/adapter/winml_adapter_dml.cpp b/winml/adapter/winml_adapter_dml.cpp index b59df6ef91..1f1740236d 100644 --- a/winml/adapter/winml_adapter_dml.cpp +++ b/winml/adapter/winml_adapter_dml.cpp @@ -22,30 +22,25 @@ namespace winmla = Windows::AI::MachineLearning::Adapter; EXTERN_C IMAGE_DOS_HEADER __ImageBase; -static std::string CurrentModulePath() { - char path[MAX_PATH]; - FAIL_FAST_IF(0 == GetModuleFileNameA((HINSTANCE)&__ImageBase, path, _countof(path))); +static std::wstring CurrentModulePath() { + WCHAR path[MAX_PATH]; + FAIL_FAST_IF(0 == GetModuleFileNameW((HINSTANCE)&__ImageBase, path, _countof(path))); - char absolute_path[MAX_PATH]; - char* name; - FAIL_FAST_IF(0 == GetFullPathNameA(path, _countof(path), absolute_path, &name)); + WCHAR absolute_path[MAX_PATH]; + WCHAR* name; + FAIL_FAST_IF(0 == GetFullPathNameW(path, _countof(path), absolute_path, &name)); - auto idx = std::distance(absolute_path, name); - auto out_path = std::string(absolute_path); - out_path.resize(idx); + auto idx = std::distance(absolute_path, name); + auto out_path = std::wstring(absolute_path); + out_path.resize(idx); - return out_path; + return out_path; } Microsoft::WRL::ComPtr CreateDmlDevice(ID3D12Device* d3d12Device) { -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) // Dynamically load DML to avoid WinML taking a static dependency on DirectML.dll - auto directml_dll = CurrentModulePath() + "\\DirectML.dll"; - wil::unique_hmodule dmlDll(LoadLibraryExA(directml_dll.c_str(), nullptr, 0)); -#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PC_APP) - wil::unique_hmodule dmlDll(LoadPackagedLibrary(L"DirectML.dll", 0)); -#endif - + auto directml_dll = CurrentModulePath() + L"DirectML.dll"; + wil::unique_hmodule dmlDll(LoadLibraryExW(directml_dll.c_str(), nullptr, 0)); THROW_LAST_ERROR_IF(!dmlDll); auto dmlCreateDevice1Fn = reinterpret_cast(