Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Microsoft.Windows.CsWin32/PointerTypeHandleInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ internal override TypeSyntaxAndMarshaling ToTypeSyntax(TypeSyntaxSettings inputs
}

TypeSyntaxAndMarshaling elementTypeDetails = this.ElementType.ToTypeSyntax(inputs with { PreferInOutRef = false }, customAttributes);
if (elementTypeDetails.MarshalAsAttribute is object || inputs.Generator?.IsManagedType(this.ElementType) is true || (inputs.PreferInOutRef && this.ElementType is PrimitiveTypeHandleInfo { PrimitiveTypeCode: not PrimitiveTypeCode.Void }))
bool xOptional = (parameterAttributes & ParameterAttributes.Optional) == ParameterAttributes.Optional;
if (elementTypeDetails.MarshalAsAttribute is object || inputs.Generator?.IsManagedType(this.ElementType) is true || (inputs.PreferInOutRef && !xOptional && this.ElementType is PrimitiveTypeHandleInfo { PrimitiveTypeCode: not PrimitiveTypeCode.Void }))
{
bool xIn = (parameterAttributes & ParameterAttributes.In) == ParameterAttributes.In;
bool xOut = (parameterAttributes & ParameterAttributes.Out) == ParameterAttributes.Out;
Expand Down
62 changes: 62 additions & 0 deletions test/GenerationSandbox.Tests/GeneratedForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.Networking.ActiveDirectory;
using Windows.Win32.System.Com;
using Windows.Win32.System.Diagnostics.Debug;
using Windows.Win32.System.Threading;

Expand Down Expand Up @@ -79,4 +80,65 @@ private static void WriteFile()
uint written = 0;
PInvoke.WriteFile((SafeHandle?)null, new byte[2], &written, (NativeOverlapped*)null);
}

private class MyStream : IStream
{
public HRESULT Read(void* pv, uint cb, uint* pcbRead)
{
// the last parameter should be a pointer because it is optional, and using `out uint` makes it very cumbersome
// for C# implementation of this interface to detect a null argument before setting the out parameter,
// which would throw NRE in such a case.
throw new NotImplementedException();
}

public HRESULT Write(void* pv, uint cb, uint* pcbWritten)
{
throw new NotImplementedException();
}

public void Seek(long dlibMove, SeekOrigin dwOrigin, ulong* plibNewPosition)
{
throw new NotImplementedException();
}

public void SetSize(ulong libNewSize)
{
throw new NotImplementedException();
}

public void CopyTo(IStream pstm, ulong cb, ulong* pcbRead, ulong* pcbWritten)
{
throw new NotImplementedException();
}

public void Commit([MarshalAs(UnmanagedType.U4)] STGC grfCommitFlags)
{
throw new NotImplementedException();
}

public void Revert()
{
throw new NotImplementedException();
}

public void LockRegion(ulong libOffset, ulong cb, [MarshalAs(UnmanagedType.U4)] LOCKTYPE dwLockType)
{
throw new NotImplementedException();
}

public void UnlockRegion(ulong libOffset, ulong cb, uint dwLockType)
{
throw new NotImplementedException();
}

public void Stat(Windows.Win32.System.Com.STATSTG* pstatstg, [MarshalAs(UnmanagedType.U4)] STATFLAG grfStatFlag)
{
throw new NotImplementedException();
}

public void Clone(out IStream ppstm)
{
throw new NotImplementedException();
}
}
}
1 change: 1 addition & 0 deletions test/GenerationSandbox.Tests/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ IEnumDebugPropertyInfo
IPersistFile
IServiceProvider
IShellWindows
IStream
KEY_EVENT_RECORD
LoadLibrary
MainAVIHeader
Expand Down
2 changes: 1 addition & 1 deletion test/SpellChecker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
IEnumString suggestions = spellChecker.Suggest(word);
do
{
suggestions.Next(suggestionResult, out _);
suggestions.Next(suggestionResult, null);
if (suggestionResult[0].Value is not null)
{
Console.WriteLine($"\t{suggestionResult[0]}");
Expand Down