Win32API: core.sys.windows: every argument name is missing.

BoQsc vaidas.boqsc at gmail.com
Wed Nov 29 14:59:40 UTC 2023


#### What should be done? What is expected?
![](https://i.imgur.com/pq1jLAo.png)

How it is currently in the 
[`core/sys/windows/winbase.d`](https://github.com/dlang/dmd/blob/a423208c7a5607a5af5e6b307f85179b7a8e9c20/druntime/src/core/sys/windows/winbase.d#L2073):
```
  BOOL WriteFile(HANDLE, PCVOID, DWORD, PDWORD, LPOVERLAPPED);
```

How it should be according to [Win32 API 
documentation](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-writefile#syntax):

```
BOOL WriteFile(
	HANDLE hFile,
	PCVOID lpBuffer,
	DWORD nNumberOfBytesToWrite,
	PDWORD lpNumberOfBytesWritten,
	LPOVERLAPPED lpOverlapped
);
```

**The names:** `hFile`, `lpBuffer`, `nNumberOfBytesToWrite`, 
`lpNumberOfBytesWritten`, `lpOverlapped` are missing.

#### Why it is important?

Without named arguments you can not use `:` syntax to set 
arguments in the function call.
```
	WriteFile(
		hFile: GetStdHandle(STD_OUTPUT_HANDLE),
```

It is important if you want your interfacing code to be more 
readable.

#### Here is a quick example with `:` and extern that corrects 
the `winbase.d` definition to allow `:` inside function call.
```
import core.sys.windows.winbase : GetStdHandle, STD_OUTPUT_HANDLE;

extern(Windows) {
	import core.sys.windows.basetsd : HANDLE;
	import core.sys.windows.windef  : BOOL, PCVOID, DWORD, PDWORD;
	import core.sys.windows.winbase : LPOVERLAPPED;

	BOOL WriteFile(HANDLE hFile, PCVOID lpBuffer, DWORD 
nNumberOfBytesToWrite, PDWORD lpNumberOfBytesWritten, 
LPOVERLAPPED lpOverlapped);
}

void main(){
	string message = "Welcome to D";
	uint bytesWritten;

	WriteFile(
		hFile: GetStdHandle(STD_OUTPUT_HANDLE),
		lpBuffer: message.ptr,
		nNumberOfBytesToWrite: message.length,
		lpNumberOfBytesWritten: &bytesWritten,
		lpOverlapped: null
	);
}
```




More information about the Digitalmars-d mailing list