diff --git a/src/Microsoft.Windows.CsWin32/Generator.FriendlyOverloads.cs b/src/Microsoft.Windows.CsWin32/Generator.FriendlyOverloads.cs index d6d2cfc0..ee7ba9be 100644 --- a/src/Microsoft.Windows.CsWin32/Generator.FriendlyOverloads.cs +++ b/src/Microsoft.Windows.CsWin32/Generator.FriendlyOverloads.cs @@ -203,8 +203,7 @@ private IEnumerable DeclareFriendlyOverloads(MethodDefi } else if ((externParam.Type is PointerTypeSyntax { ElementType: TypeSyntax ptrElementType } && !IsVoid(ptrElementType) - && !this.IsInterface(parameterTypeInfo) - && this.canUseSpan) || + && !this.IsInterface(parameterTypeInfo)) || externParam.Type is ArrayTypeSyntax) { TypeSyntax elementType = externParam.Type is PointerTypeSyntax ptr ? ptr.ElementType @@ -249,6 +248,7 @@ private IEnumerable DeclareFriendlyOverloads(MethodDefi // It is possible that sizeParamIndex points to a parameter that is not on the extern method // when the parameter is the last one and was moved to a return value. if (sizeParamIndex.HasValue + && this.canUseSpan && externMethodDeclaration.ParameterList.Parameters.Count > sizeParamIndex.Value && !(externMethodDeclaration.ParameterList.Parameters[sizeParamIndex.Value].Type is PointerTypeSyntax) && !(externMethodDeclaration.ParameterList.Parameters[sizeParamIndex.Value].Modifiers.Any(SyntaxKind.OutKeyword) || externMethodDeclaration.ParameterList.Parameters[sizeParamIndex.Value].Modifiers.Any(SyntaxKind.RefKeyword)) diff --git a/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs b/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs index 154b1fe6..7457cae5 100644 --- a/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs +++ b/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs @@ -48,6 +48,17 @@ public void TryGetEnumName(string candidate, string? declaringEnum) Assert.Equal(declaringEnum, actualDeclaringEnum); } + [Theory] + [MemberData(nameof(TFMData))] + public void CoCreateInstance(string tfm) + { + this.compilation = this.starterCompilations[tfm]; + this.generator = this.CreateGenerator(includeDocs: true); + Assert.True(this.generator.TryGenerateExternMethod("CoCreateInstance", out _)); + this.CollectGeneratedCode(this.generator); + this.AssertNoDiagnostics(); + } + [Theory] [MemberData(nameof(TFMData))] public void SimplestMethod(string tfm)