Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode Compiler Error Fix #214

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

AMZN-Gene
Copy link

@AMZN-Gene AMZN-Gene commented Dec 3, 2024

Using TCHAR string to fix compiler error when compiling with UNICODE
TCHAR automatically resolves to wchar or char depending if unicode is enabled or not.

Resolves #213

HANDLE hFile =
CreateFile(filepath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr,
CreateFile(tFilepath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr,
Copy link

@spham-amzn spham-amzn Dec 3, 2024

Choose a reason for hiding this comment

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

Instead of possibly converting the filename to a char or wide character, why no use CreateFileA directly so it always uses char? CreateFile is really a macro that switches between CreateFileA and CreateFileW based on the unicode switch anyways

@syoyo
Copy link
Collaborator

syoyo commented Dec 4, 2024

Personally I don't like TCHAR approach.

Filename in USD is usually UTF8, so we can assume input string(in std::string) is UTF8 encoded, and it'd be better to use CreateFileW (WideChar version of API), by converting UTF8 string to widechar string(UTF16LE in Windows).

Please take a look at a code fragment in TinyEXR: https://github.com/syoyo/tinyexr/blob/5fcb4dcb6e3abf96214b67e5c54db1ceec6a455c/tinyexr.h#L6746

The same implementation is also used in OpenUSD: PixarAnimationStudios/OpenUSD#1580

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.

Visual Studio Compile Fail when Unicode Enabled: CreateFile() Requires LPCWSTR File Name
4 participants