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

Closed

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

@syoyo syoyo added the bug Something isn't working label Dec 20, 2024
@syoyo
Copy link
Collaborator

syoyo commented Dec 20, 2024

I've fixed the issue in another branch.

857a539

It always uses CreateFileW/Widechar(UTF16LE) interface.

It also provides std::wstring interface for MMapFile(Windows only)

I'll merge mmap_file branch after some tests.

@AMZN-Gene
Copy link
Author

Beautiful! Sorry I was pulled away from this for a while, but @syoyo fixed it!

@AMZN-Gene AMZN-Gene closed this Dec 20, 2024
@AMZN-Gene AMZN-Gene deleted the GHI-213_UnicodeCompileFix branch December 20, 2024 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
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