dart-lang / dart-lang/native

How to generate bindings for Windows headers?

Open
#477 1 comment 0 reactions 0 assignees View on GitHub
package:ffigen
Dominant language
Dart
Stars
275
Forks
144
Avg merge
2d 10h
Merged PRs (30d)
47

Description

I'm trying to generate bindings for [this](https://learn.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpgetieproxyconfigforcurrentuser) specific function, but I have a lot of warnings and errors in console and generated file is empty.

ffigen.yaml

```yaml
# Run with `flutter pub run ffigen --config ffigen.yaml`.
name: WinHttpBindings
description: |
Bindings for `Winhttp.h`.

Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
output: 'lib/src/winhttp.g.dart'
headers:
entry-points:
- 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h'
include-directives:
- 'C:\Program Files (x86)\Windows Kits\10\Include\**'
- 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\WinBase.h'
compiler-opts:
- '-I "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\"'
exclude-all-by-default: true
preamble: |
// ignore_for_file: type=lint
comments:
style: any
length: full
functions:
include:
- WinHttpGetIEProxyConfigForCurrentUser
```

Output

```
flutter pub run ffigen --config ffigen.yaml
Running in Directory: 'S:\src\system_proxy_resolver\system_proxy_resolver_windows'
Input Headers: [C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h]
[SEVERE] : Header C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h: Total errors/warnings: 21.
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:29:10: warning: the current #pragma pack alignment value is modified in the included
file [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:53:9: error: unknown type name 'LPVOID' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:56:9: error: unknown type name 'WORD' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:103:5: error: unknown type name 'DWORD_PTR' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:104:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:114:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:115:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:152:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:153:5: error: unknown type name 'LPWSTR' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:154:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:156:5: error: unknown type name 'LPWSTR' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:157:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:159:5: error: unknown type name 'LPWSTR' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:160:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:161:5: error: unknown type name 'LPWSTR' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:162:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:163:5: error: unknown type name 'LPWSTR' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:164:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:165:5: error: unknown type name 'LPWSTR' [Semantic Issue]
[SEVERE] : C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winhttp.h:166:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : fatal error: too many errors emitted, stopping now
Finished, Bindings generated in S:\src\system_proxy_resolver\system_proxy_resolver_windows\.\lib\src\winhttp.g.dart
```

I had this issue before, and I partially solved it by switching to `cygwin` headers instead of Microsoft's ones. But when I try this approach for WinHTTP headers I get the same results.

ffigen.yaml 2

```yaml
# Run with `flutter pub run ffigen --config ffigen.yaml`.
name: WinHttpBindings
description: |
Bindings for `Winhttp.h`.

Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
output: 'lib/src/winhttp.g.dart'
headers:
entry-points:
- 'C:\cygwin64\usr\include\w32api\winhttp.h'
include-directives:
- 'C:\cygwin64\usr\include\w32api\**'
compiler-opts:
- '-I "C:\cygwin64\usr\include\w32api"'
exclude-all-by-default: true
preamble: |
// ignore_for_file: type=lint
comments:
style: any
length: full
functions:
include:
- WinHttpGetIEProxyConfigForCurrentUser
```

Output 2

```
flutter pub run ffigen --config ffigen.yaml
Running in Directory: 'S:\src\system_proxy_resolver\system_proxy_resolver_windows'
Input Headers: [C:\cygwin64\usr\include\w32api\winhttp.h]
[SEVERE] : Header C:\cygwin64\usr\include\w32api\winhttp.h: Total errors/warnings: 21.
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:23:10: warning: the current #pragma pack alignment value is modified in the included file [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:32:9: error: unknown type name 'LPVOID' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:38:9: error: unknown type name 'WORD' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:531:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:532:5: error: unknown type name 'LPWSTR' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:533:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:535:5: error: unknown type name 'LPWSTR' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:536:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:538:5: error: unknown type name 'LPWSTR' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:539:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:540:5: error: unknown type name 'LPWSTR' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:541:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:542:5: error: unknown type name 'LPWSTR' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:543:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:544:5: error: unknown type name 'LPWSTR' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:545:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:552:5: error: unknown type name 'DWORD_PTR' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:553:5: error: unknown type name 'DWORD' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:558:5: error: unknown type name 'FILETIME' [Semantic Issue]
[SEVERE] : C:\cygwin64\usr\include\w32api\winhttp.h:559:5: error: unknown type name 'FILETIME' [Semantic Issue]
[SEVERE] : fatal error: too many errors emitted, stopping now
Finished, Bindings generated in S:\src\system_proxy_resolver\system_proxy_resolver_windows\.\lib\src\winhttp.g.dart
```

I think that the following issues are related to my problem dart-lang/native#481 dart-lang/native#474.

Can you provide a working example how to generate bindings for win32 headers? Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.