www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Win32API: core.sys.windows: every argument name is missing.

reply BoQsc <vaidas.boqsc gmail.com> writes:

![](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.



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.


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
	);
}
```
Nov 29 2023
parent reply DrDread <DrDread cheese.com> writes:
On Wednesday, 29 November 2023 at 14:59:40 UTC, BoQsc wrote:

 ![](https://i.imgur.com/pq1jLAo.png)

 [...]
I 100% support your request. please add those names. makes IDE support so much more useful if i can see what the parameter is supposed to do
Nov 29 2023
parent reply BoQsc <vaidas.boqsc gmail.com> writes:
If I'm not mistaken, reviving the idea of 
[windows-d](https://github.com/rumbu13/windows-d/tree/master) 
project would allow to generate Windows Headers in a more 
automated standard way.

By inspecting the [example 
output](https://github.com/rumbu13/windows-d/blob/master/out/windows/wininet.d)
it seems to be promising thing, if introduced into D Lang ecosystem. Replacing
the old Public Domain handwritten MinGW reverse-engineered header translations.

![](https://i.imgur.com/CST3Rbq.png)
[link to the source code seen in the 
image](https://github.com/dlang/dmd/blob/a423208c7a5607a5af5e6b307f85179b7a8e9c20/druntime/src/core/sys/windows/winbase.d#L1-L8)


Related article:
https://blogs.windows.com/windowsdeveloper/2021/01/21/making-win32-apis-more-accessible-to-more-languages/
Nov 30 2023
parent reply Adam Wilson <flyboynw gmail.com> writes:
On Thursday, 30 November 2023 at 11:49:26 UTC, BoQsc wrote:
 If I'm not mistaken, reviving the idea of 
 [windows-d](https://github.com/rumbu13/windows-d/tree/master) 
 project would allow to generate Windows Headers in a more 
 automated standard way.
This is a known issue. One of the goals of ImportC is to make it possible to import the Windows headers in a completely automated way. We'll never be able to import all of the headers due to some of the strangeness in them, but we should be able to get most of them. ImportC generated DI files do include the parameter names. Another deficiency of these files is that they are from the Windows Vista/7 era and are missing large chunks of the modern Windows API. If you want to try ImportC on windows headers I'd be curious to hear how it goes, and please file bugs!
Nov 30 2023
next sibling parent Kagamin <spam here.lot> writes:
see 
https://forum.dlang.org/post/swmmlsaoefhrtansanfy forum.dlang.org
Dec 01 2023
prev sibling parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On Friday, 1 December 2023 at 06:20:33 UTC, Adam Wilson wrote:
 On Thursday, 30 November 2023 at 11:49:26 UTC, BoQsc wrote:
 If I'm not mistaken, reviving the idea of 
 [windows-d](https://github.com/rumbu13/windows-d/tree/master) 
 project would allow to generate Windows Headers in a more 
 automated standard way.
This is a known issue. One of the goals of ImportC is to make it possible to import the Windows headers in a completely automated way. We'll never be able to import all of the headers due to some of the strangeness in them, but we should be able to get most of them.
I fear that “most” is not good enough. You either have 100% correct binding or be prepared to debug the missing pieces instead of writing your application. —— Dmitry Olshansky
Dec 01 2023
parent Adam Wilson <flyboynw gmail.com> writes:
On Friday, 1 December 2023 at 09:43:57 UTC, Dmitry Olshansky 
wrote:
 I fear that “most” is not good enough. You either have 100% 
 correct binding or be prepared to debug the missing pieces 
 instead of writing your application.

 ——
 Dmitry Olshansky
That's not significantly different or worse from the present situation where all of the APIs from any version of Windows after 7 are simply missing.
Dec 02 2023