-
Notifications
You must be signed in to change notification settings - Fork 120
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
[Feature Request] Attribute for ANSI/Unicode Suffix #711
Comments
Unfortunately that information isn't available from the headers. We would need to build up a big list of them and apply attributes when we generate the .winmd. |
For what its worth, the Rust projection simply provides both A and W functions unchanged and the developer decides which to use. |
Thanks for the quick reply both of you. @kennykerr, yeah, that's a possibility here, but it creates lots of micro-frictions:
@sotteson1, that's essentially what I'm having to do within the projection. I believe there's a semi-heuristic approach here, however:
|
In CsWin32 we generate structs only when asked for or when another API that was requested requires it. In those cases, we only need to generate one struct anyway (to match the request), and we leave the suffix in place. Functions don't tend to be named in all caps, and CsWin32 has a cheap and seemingly adequate check on the name to assign it to narrow or wide character sets, and then we ignore all the ansi functions where a wide char version exists unless the user specifically asks for them. |
BTW: the narrow character structs and APIs are not "ansi", as I understand it. They are whatever the process's current codepage states. They may be UTF-8 or it may be "Windows code page 1252", but may be any of a number of other 8-bit character codepages. |
Yeah, your (Microsoft's) docs need fixing for consistency here :) I don't know if this is true in the world of UTF-8, but the recommendation on this page is to just use Unicode:
|
In my JSON projection I programmatically identify the A/W variants and include them in a list in each Namespace, i.e. ,"UnicodeAliases":[
"WIN32_FIND_DATA"
,"NTMS_DRIVEINFORMATION"
,"NTMS_CHANGERINFORMATION"
,"NTMS_PMIDINFORMATION"
,"NTMS_PARTITIONINFORMATION"
,"NTMS_DRIVETYPEINFORMATION"
,"NTMS_CHANGERTYPEINFORMATION"
,"NTMS_LIBREQUESTINFORMATION"
,"NTMS_OPREQUESTINFORMATION"
,"NTMS_OBJECTINFORMATION"
,"NTMS_I1_LIBREQUESTINFORMATION"
,"NTMS_I1_PMIDINFORMATION"
,"NTMS_I1_PARTITIONINFORMATION"
,"NTMS_I1_OPREQUESTINFORMATION"
,"NTMS_I1_OBJECTINFORMATION"
,"SearchPath"
,"CreateDirectory"
,"CreateFile"
,"DefineDosDevice" The algorithm to identify them is fairly straightforward. Most of the code is contained within this It takes all the top level symbols and detects if they end with It's simple enough that each projection could implement this themselves, or the metadata could also leverage this logic to include this information somehow. P.S. You also need to track all the symbols that don't end in A/W and verify that the base symbol for the ones that do end in A/W isn't already defined. There's a few dozen symbols where this applies. |
What would the attribute(s) look like? |
Ansi variants are now decorated with |
It would be incredibly helpful if there was a way to programmatically identify structs and functions that have a
A
/W
suffix that denotes whether a Win32 API is ANSI / Unicode.I mask this from consumers of my projection (as indeed, C does through the use of
#define
macros), which means that I strip off the suffix. But there's no easy heuristic for me to differentiate between (say)Windows.Win32.UI.Controls.TBBUTTONINFOA
(an ANSI struct) andWindows.Win32.Devices.BiometricFramework.WINBIO_UNIT_SCHEMA
(a struct that is neither).I could create an elaborate exclusion list of false positives in my projection, but this really belongs in the source metadata, I think.
The text was updated successfully, but these errors were encountered: