Skip to content

Commit

Permalink
Merge pull request #764 from microsoft/fix761
Browse files Browse the repository at this point in the history
Use Windows active code page instead of UTF8 for decoding narrow characters
  • Loading branch information
AArnott committed Nov 11, 2022
2 parents c3de6fe + a8a9012 commit 0d43ba7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Microsoft.Windows.CsWin32/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4967,15 +4967,15 @@ private IEnumerable<MethodDeclarationSyntax> DeclareFriendlyOverloads(MethodDefi
parameters[param.SequenceNumber - 1] = externParam
.WithType(PredefinedType(TokenWithSpace(SyntaxKind.StringKeyword)));

// fixed (byte* someLocal = some is object ? System.Text.Encoding.UTF8.GetBytes(some) : null)
// fixed (byte* someLocal = some is object ? System.Text.Encoding.Default.GetBytes(some) : null)
fixedBlocks.Add(VariableDeclaration(PointerType(PredefinedType(Token(SyntaxKind.ByteKeyword)))).AddVariables(
VariableDeclarator(localName.Identifier).WithInitializer(EqualsValueClause(
ConditionalExpression(
BinaryExpression(SyntaxKind.IsExpression, origName, PredefinedType(Token(SyntaxKind.ObjectKeyword))),
InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
ParseTypeName("global::System.Text.Encoding.UTF8"),
ParseTypeName("global::System.Text.Encoding.Default"),
IdentifierName(nameof(Encoding.GetBytes))))
.WithArgumentList(
ArgumentList(
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Windows.CsWin32/templates/PCSTR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal int Length
/// Returns a <see langword="string"/> with a copy of this character array, decoding as UTF-8.
/// </summary>
/// <returns>A <see langword="string"/>, or <see langword="null"/> if <see cref="Value"/> is <see langword="null"/>.</returns>
public override string ToString() => this.Value is null ? null : new string((sbyte*)this.Value, 0, this.Length, global::System.Text.Encoding.UTF8);
public override string ToString() => this.Value is null ? null : new string((sbyte*)this.Value, 0, this.Length, global::System.Text.Encoding.Default);

#if canUseSpan
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Windows.CsWin32/templates/PCZZSTR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal int Length
/// Returns a <see langword="string"/> with a copy of this character array, decoding as UTF-8.
/// </summary>
/// <returns>A <see langword="string"/>, or <see langword="null"/> if <see cref="Value"/> is <see langword="null"/>.</returns>
public override string ToString() => this.Value is null ? null : new string((sbyte*)this.Value, 0, this.Length, global::System.Text.Encoding.UTF8);
public override string ToString() => this.Value is null ? null : new string((sbyte*)this.Value, 0, this.Length, global::System.Text.Encoding.Default);

#if canUseSpan
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion test/GenerationSandbox.Tests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public void StructCharFieldsMarshaledAsUtf16()
}

[Fact]
public void CHAR_MarshaledAsUtf8()
public void CHAR_MarshaledAsAnsi()
{
Assert.Equal(1, Marshal.SizeOf<CHAR>());
}
Expand Down

0 comments on commit 0d43ba7

Please sign in to comment.