Skip to content

Use Wide String variants explicitly for Windows API calls#7235

Merged
bob80905 merged 1 commit intomicrosoft:mainfrom
bob80905:UseWStrVariantsExplicitly
Mar 20, 2025
Merged

Use Wide String variants explicitly for Windows API calls#7235
bob80905 merged 1 commit intomicrosoft:mainfrom
bob80905:UseWStrVariantsExplicitly

Conversation

@bob80905
Copy link
Copy Markdown
Collaborator

This PR changes some code in ExecutionTests.cpp to use the wide string variants of Windows API calls explicitly. This is because some internal builds will get confused about which overload to resolve the GetModuleHandle function to. By being explicit, this should eliminate the error that an arg can't be converted to LPCWSTR.

CHAR szFullModuleFilePath[MAX_PATH] = "";
GetModuleFileName(GetModuleHandle("d3d10warp.dll"),
szFullModuleFilePath, sizeof(szFullModuleFilePath));
if (GetModuleHandleW(L"d3d10warp.dll") != NULL) {
Copy link
Copy Markdown
Collaborator

@farzonl farzonl Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks good. However, I've seen projects where the use of the W api function vs the char one was controlled via a compile time flag. Would there be any reason to do that here?

Copy link
Copy Markdown
Contributor

@tex3d tex3d Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there have been projects that do this. However, our char strings are not ASCII or based on some current global character set, they are utf-8. The char APIs are not Unicode. Therefore, we should always use the Unicode wide string APIs. We have no reason to ever build for the non-Unicode APIs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, this is the reason for all the forced conversions in the DXC API. The only Unicode API style for Windows (and thus COM APIs) is the wide string APIs, yet we internally use char strings representing Unicode in UTF-8 encoding.

bob80905 added a commit that referenced this pull request Mar 20, 2025
This PR changes some code in ExecutionTests.cpp to use the wide string
variants of Windows API calls explicitly. This is because some internal
builds will get confused about which overload to resolve the
GetModuleHandle function to. By being explicit, this should eliminate
the error that an arg can't be converted to LPCWSTR.

Cherry picked from
#7235
@bob80905 bob80905 merged commit 8b3fae2 into microsoft:main Mar 20, 2025
13 checks passed
@github-project-automation github-project-automation Bot moved this from New to Done in HLSL Roadmap Mar 20, 2025
madebr pushed a commit to libsdl-org/DirectXShaderCompiler that referenced this pull request Dec 3, 2025
…7236)

This PR changes some code in ExecutionTests.cpp to use the wide string
variants of Windows API calls explicitly. This is because some internal
builds will get confused about which overload to resolve the
GetModuleHandle function to. By being explicit, this should eliminate
the error that an arg can't be converted to LPCWSTR.

Cherry picked from
microsoft#7235

(cherry picked from commit 2399215)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants