commit 2e14846ad20b2981028831cd20b5b2fe4b080845
parent 7dcc3c3eeb3bab57e9594fde8c8d2a2c767bbfe1
Author: JohnMcPMS <johnmcp@microsoft.com>
Date: Fri, 19 Apr 2024 10:00:37 -0700
Make DLL directory work in packaged cases as well (#4389)
## Change
Move the code that enables our .winmd to be found by the PS module out
of the unpackaged conditional block. It will now be run if we failed to
find a result for any reason.
Diffstat:
1 file changed, 30 insertions(+), 23 deletions(-)
diff --git a/src/Xlang/UndockedRegFreeWinRT/src/UndockedRegFreeWinRT/UndockedRegFreeWinRT/typeresolution.cpp b/src/Xlang/UndockedRegFreeWinRT/src/UndockedRegFreeWinRT/UndockedRegFreeWinRT/typeresolution.cpp
@@ -481,8 +481,8 @@ namespace UndockedRegFreeWinRT
const UINT32 filter = PACKAGE_FILTER_HEAD | PACKAGE_FILTER_DIRECT | PACKAGE_FILTER_IS_IN_RELATED_SET;
hr = HRESULT_FROM_WIN32(GetCurrentPackageInfo(filter, &dwBufferLength, nullptr, &dwPackagesCount));
- // Only find the type if the it is a unpacakged app. Packaged apps can have their exe on their package graph,
- // which will allow type resolution against adjacent WinMDs.
+ // Only find the type next to the exe if the it is an unpackaged app. Packaged apps can have their exe on
+ // their package graph, which will allow type resolution against adjacent WinMDs.
if (hr == HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE))
{
PCWSTR exeDir = nullptr; // Never freed; owned by process global.
@@ -498,31 +498,38 @@ namespace UndockedRegFreeWinRT
if (hr == RO_E_METADATA_NAME_NOT_FOUND)
{
- PCWSTR dllDir = nullptr; // Never freed; owned by process global.
- RETURN_IF_FAILED(GetProcessDllDir(&dllDir));
-
- hr = FindTypeInDirectoryWithNormalization(
- pMetaDataDispenser,
- pszFullName,
- dllDir,
- phstrMetaDataFilePath,
- ppMetaDataImport,
- pmdTypeDef);
-
- if (hr == RO_E_METADATA_NAME_NOT_FOUND)
- {
- // For compatibility purposes, if we fail to find the type in the unpackaged location, we should return
- // HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE) instead of a "not found" error. This preserves the
- // behavior that existed before unpackaged type resolution was implemented.
- hr = HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE);
- }
+ // For compatibility purposes, if we fail to find the type in the unpackaged location, we should return
+ // HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE) instead of a "not found" error. This preserves the
+ // behavior that existed before unpackaged type resolution was implemented.
+ hr = HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE);
}
- return hr;
}
else
{
- return RO_E_METADATA_NAME_NOT_FOUND;
- }
+ hr = RO_E_METADATA_NAME_NOT_FOUND;
+ }
+
+ // If not successful looking next to an unpackaged exe, try looking next to our DLL.
+ if (FAILED(hr))
+ {
+ PCWSTR dllDir = nullptr; // Never freed; owned by process global.
+ RETURN_IF_FAILED(GetProcessDllDir(&dllDir));
+
+ HRESULT dllHR = FindTypeInDirectoryWithNormalization(
+ pMetaDataDispenser,
+ pszFullName,
+ dllDir,
+ phstrMetaDataFilePath,
+ ppMetaDataImport,
+ pmdTypeDef);
+
+ if (SUCCEEDED(dllHR))
+ {
+ hr = dllHR;
+ }
+ }
+
+ return hr;
}
//