mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-15 14:15:54 -06:00
[GH-ISSUE #190] Incompatible LPWSTR typedef #125
Labels
No labels
bug
enhancement
help wanted
help wanted
pull-request
question
todo
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/qmlnet#125
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @shartte on GitHub (Apr 13, 2020).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/190
This is more of a question/discussion than an actual bug.
Why is LPWSTR typedef'd to be char16_t rather than wchar_t?
I can guess why. wchar_t's size is implementation defined, but
UnmanagedType.LPWStrguarantees 2-byte per character.The issue that arises from typedefing LPWSTR in QMLNet's headers is that if it is mixed with code that includes windows.h, it will not compile anymore, since wchar_t and char16_t are NOT interchangeable:
If there's no other reason for it, I'd propose changing the native method declarations over to
const char16_t*and removing the typedef. I am willing to make the PR for that ofcourse.@pauldotknopf commented on GitHub (Apr 13, 2020):
I don't have a problem with that. Either change everything to
const char16_t*, or create our owntypedefthat doesn't collide withwindows.h.@shartte commented on GitHub (Apr 13, 2020):
Just for completeness sake: I just checked QString::fromUtf16 again, and it says the following:
Does anyone know why that is?
@pauldotknopf commented on GitHub (Apr 13, 2020):
Not me :)
@vadi2 commented on GitHub (Apr 13, 2020):
Thiago on #qt might know.
@shartte commented on GitHub (May 23, 2020):
@pauldotknopf Thinking about this some more: Why don't we just use QChar* directly?
We don't actually do any conversion on the raw character data and it would save us the nasty reinterpret_cast that's otherwise needed.
Ofcourse the docs say "Most compilers treat it like an unsigned short." without actually specifying what "most" means. Although we might guard against this with a static_assert(sizeof(QChar) == 2).
The
char16_tconstructor certainly makes it look like we can just use them interchangeably:@pauldotknopf commented on GitHub (May 26, 2020):
I'm not sure. I always thought
QCharwasn't blittable with standardchar16_t, but it looks like I'm wrong.@shartte commented on GitHub (May 29, 2020):
Fixed by #203