Skip to content

ReadFile and WriteFile do not match with .NET overlapped structure #545

@raffaeler

Description

@raffaeler

Actual behavior

The signature generated for the ReadFile and WriteFile structures is:

internal static unsafe winmdroot.Foundation.BOOL WriteFile(SafeHandle hFile, void* lpBuffer,
    uint nNumberOfBytesToWrite, uint* lpNumberOfBytesWritten,
    winmdroot.System.IO.OVERLAPPED* lpOverlapped) {}

On the other hand, .NET already defines System.Threading.NativeOverlapped which must be used with ThreadPoolBoundHandle.GetNativeOverlappedState and other APIs.

As a consequence, when using the asynchronous behaviour on Windows, I can't rely on the generated code, but I have to define separately the PInvokes.

Please note that this is also true for other APIs like:

  • GetOverlappedResult
  • ClearCommError
  • WaitCommEvent
  • WIN32_ERROR (must be casted to match Marshal.GetLastWin32Error()

Expected behavior

Whenever .NET defines some interop code, I expect the generated code matches them. Or at least provides a different overload with a native pointer so that it can be used with code different than the one created by the genrator.
In general, when there is a pointer, it would be useful to get overloads with a "void*" to avoid being blocked.

Repro steps

  1. NativeMethods.txt content:
CreateFile
ReadFile
WriteFile
GetOverlappedResult
CloseHandle
  1. NativeMethods.json content (if present):

N/A

  1. Any of your own code that should be shared?

Not needed

Context

  • CsWin32 version: <PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.647-beta">
  • Win32Metadata version: N/A
  • Target Framework: net6.0
  • LangVersion : N/A

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions