Skip to content

Conversation

@oldnewthing
Copy link
Member

This avoids DLL planting issues during the fallback search for a base trust server. It uses the LOAD_LIBRARY_SEARCH_DEFAULT_DIRS flag, which searches the usual places, including the application directory, but excludes the current directory. The flag is supported on Win8 onward, as well as on Win7 if you have KB2533623 installed (which you really should). If you need to support versions of Win7 that haven't been patched since 2011, then stick with whatever version of C++/WinRT you are currently using.

This avoids DLL planting issues during the fallback search
for a base trust server. It uses the `LOAD_LIBRARY_SEARCH_DEFAULT_DIRS`
flag, which searches the usual places, including the application directory,
but exclude the current directory. The flag is supported on Win8 onward,
as well as on Win7 if you have KB2533623 installed (which you really should).
If you need to support versions of Win7 that haven't been patched
since 2011, then stick with whatever version of C++/WinRT you are
currently using.
@jlaanstra
Copy link
Contributor

Do we want to allow customization of the default, maybe via a #define?

@sylveon
Copy link
Contributor

sylveon commented Mar 30, 2023

I'm not sure it's worth the expense of adding a customization switch to support operating systems that haven't been patched since 2011

@kennykerr
Copy link
Collaborator

Right, the switch is to use a different version of cppwinrt.

@jonthysell
Copy link

For RNW we're going to do this:

#ifdef CPPWINRT_USE_LOADLIBRARYEXW
#define WINRT_IMPL_LoadLibraryW(name) \
  WINRT_IMPL_LoadLibraryExW(name, nullptr, 0x00001000 /* LOAD_LIBRARY_SEARCH_DEFAULT_DIRS */)
#endif

where CPPWINRT_USE_LOADLIBRARYEXW is defined via a MSBUILD version check:

  <ItemDefinitionGroup Label="CppWinRT">
    <ClCompile>
      <PreprocessorDefinitions Condition="$([MSBuild]::VersionGreaterThanOrEquals('$(CppWinRTVersion)', '2.0.230524.3'))">
        CPPWINRT_USE_LOADLIBRARYEXW;
        %(PreprocessorDefinitions)
      </PreprocessorDefinitions>
    </ClCompile>
  </ItemDefinitionGroup>

because of the lack of convenient version macros to do it strictly in code: #668.

@oldnewthing
Copy link
Member Author

@jonthysell Note that all WINRT_IMPL_* names are reserved for internal use by C++/WinRT and are considered off-limits to apps.

In all namespaces, names beginning with WINRT_IMPL_ are reserved for C++/WinRT, and you shouldn't use them in your application.

If you want to call LoadLibrary, you can define your own RNW_LoadLibraryW function.

jonthysell added a commit to microsoft/react-native-windows that referenced this pull request Jul 28, 2023
…xW (#11953)

## Description

CppWinRT >= 2.0.230524.3 no longer expose the `WINRT_IMPL_LoadLibraryW` method for loading libraries, instead preferring a new `WINRT_IMPL_LoadLibraryExW`. See microsoft/cppwinrt#1293.

This PR fixes our usage of `WINRT_IMPL_LoadLibraryW` by detecting newer versions of CppWinRT and using the new API when available.

### Type of Change
- Bug fix (non-breaking change which fixes an issue)

### Why
Customers who tried to specify newer versions of CppWinRT hit build errors due to the use of the deprecated API.

Closes #11795

### What
Created a macro to re-define the old API which calls the new API with the same behavior, as seen in the PR which deprecated the API in the first place.

## Screenshots
N/A

## Testing
Verified able to build against the latest [Microsoft.Windows.CppWinRT 2.0.230706.1](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.230706.1).

## Changelog
Should this change be included in the release notes: yes

Customers who specify their own version of Microsoft.Windows.CppWinRT can now use versions >= 2.0.230524.3.
jonthysell added a commit to jonthysell/react-native-windows that referenced this pull request Aug 7, 2023
…ibraryExW

This PR backports microsoft#11953 to RNW 0.72.

CppWinRT >= 2.0.230524.3 no longer expose the `WINRT_IMPL_LoadLibraryW` method for loading libraries, instead preferring a new `WINRT_IMPL_LoadLibraryExW`. See microsoft/cppwinrt#1293.

This PR fixes our usage of `WINRT_IMPL_LoadLibraryW` by detecting newer versions of CppWinRT and using the new API when available.

- Bug fix (non-breaking change which fixes an issue)

Customers who tried to specify newer versions of CppWinRT hit build errors due to the use of the deprecated API.

Closes microsoft#11795

Created a macro to re-define the old API which calls the new API with the same behavior, as seen in the PR which deprecated the API in the first place.

N/A

Verified able to build against the latest [Microsoft.Windows.CppWinRT 2.0.230706.1](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.230706.1).

Should this change be included in the release notes: yes

Customers who specify their own version of Microsoft.Windows.CppWinRT can now use versions >= 2.0.230524.3.
jonthysell added a commit to jonthysell/react-native-windows that referenced this pull request Aug 7, 2023
…ibraryExW

This PR backports microsoft#11953 to RNW 0.72.

CppWinRT >= 2.0.230524.3 no longer expose the `WINRT_IMPL_LoadLibraryW` method for loading libraries, instead preferring a new `WINRT_IMPL_LoadLibraryExW`. See microsoft/cppwinrt#1293.

This PR fixes our usage of `WINRT_IMPL_LoadLibraryW` by detecting newer versions of CppWinRT and using the new API when available.

- Bug fix (non-breaking change which fixes an issue)

Customers who tried to specify newer versions of CppWinRT hit build errors due to the use of the deprecated API.

Closes microsoft#11795

Created a macro to re-define the old API which calls the new API with the same behavior, as seen in the PR which deprecated the API in the first place.

N/A

Verified able to build against the latest [Microsoft.Windows.CppWinRT 2.0.230706.1](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.230706.1).

Should this change be included in the release notes: yes

Customers who specify their own version of Microsoft.Windows.CppWinRT can now use versions >= 2.0.230524.3.

Enable using newer CppWinRT versions that use WINRT_IMPL_LoadLibraryExW (microsoft#11953)

CppWinRT >= 2.0.230524.3 no longer expose the `WINRT_IMPL_LoadLibraryW` method for loading libraries, instead preferring a new `WINRT_IMPL_LoadLibraryExW`. See microsoft/cppwinrt#1293.

This PR fixes our usage of `WINRT_IMPL_LoadLibraryW` by detecting newer versions of CppWinRT and using the new API when available.

- Bug fix (non-breaking change which fixes an issue)

Customers who tried to specify newer versions of CppWinRT hit build errors due to the use of the deprecated API.

Closes microsoft#11795

Created a macro to re-define the old API which calls the new API with the same behavior, as seen in the PR which deprecated the API in the first place.

N/A

Verified able to build against the latest [Microsoft.Windows.CppWinRT 2.0.230706.1](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.230706.1).

Should this change be included in the release notes: yes

Customers who specify their own version of Microsoft.Windows.CppWinRT can now use versions >= 2.0.230524.3.
jonthysell added a commit to microsoft/react-native-windows that referenced this pull request Aug 7, 2023
…ibraryExW (#11986)

This PR backports #11953 to RNW 0.72.

## Description

CppWinRT >= 2.0.230524.3 no longer expose the `WINRT_IMPL_LoadLibraryW` method for loading libraries, instead preferring a new `WINRT_IMPL_LoadLibraryExW`. See microsoft/cppwinrt#1293.

This PR fixes our usage of `WINRT_IMPL_LoadLibraryW` by detecting newer versions of CppWinRT and using the new API when available.

### Type of Change
- Bug fix (non-breaking change which fixes an issue)

### Why
Customers who tried to specify newer versions of CppWinRT hit build errors due to the use of the deprecated API.

Closes #11795

### What
Created a macro to re-define the old API which calls the new API with the same behavior, as seen in the PR which deprecated the API in the first place.

## Screenshots
N/A

## Testing
Verified able to build against the latest [Microsoft.Windows.CppWinRT 2.0.230706.1](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.230706.1).

## Changelog
Should this change be included in the release notes: yes

Customers who specify their own version of Microsoft.Windows.CppWinRT can now use versions >= 2.0.230524.3.
@kennykerr kennykerr mentioned this pull request Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants