Skip to content

Commit

Permalink
Merge pull request #690 from dart-windows/v4
Browse files Browse the repository at this point in the history
v4 sustained engineering updates
  • Loading branch information
timsneath committed May 6, 2023
2 parents 854e631 + f134993 commit 61efad5
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 2 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 4.1.4

- Add some minor network APIs

## 4.1.3

- Add registry constants for win32_registry (#682)

## 4.1.2

- Fix missing export of crypt32 APIs (#673)
- Fix a dartdoc comment reference (#666)
- Fix memory leak in `convertToHString

## 4.1.1

- Convert acronyms in method/property names to lowercase (#649, @halildurmus)
Expand Down Expand Up @@ -38,6 +52,10 @@
- Add APIs for shell file operations (#630, @timsneath)
- Update upper Dart SDK constraint to explicitly support Dart 3

## 3.1.4

- Fix missing export of crypt32 APIs

## 3.1.3

- Restructure generator util to use JSON for all data files (#605, @timsneath)
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

A package that wraps some of the most common Win32 API calls using FFI to make
them accessible to Dart code without requiring a C compiler or the Windows SDK.
Part of the (Dart | Windows)[https://github.com/dart-windows] suite of Windows
packages.

[![pub package](https://img.shields.io/pub/v/win32.svg)](https://pub.dev/packages/win32)
[![Language](https://img.shields.io/badge/language-Dart-blue.svg)](https://dart.dev)
Expand All @@ -14,8 +16,8 @@ By design, this package provides minimal modifications to the Win32 API to
support Dart idioms. The goal is to provide high familiarity to an existing
Windows developer. Other Dart packages may build on these primitives to provide
a friendly API for Dart and Flutter developers. A good example of that is
[filepicker_windows](https://pub.dev/packages/filepicker_windows), which offers
a common item dialog suitable for incorporation into an existing Flutter app.
[win32_registry](https://pub.dev/packages/win32_registry), which offers a set of
APIs for accessing the Windows registry that don't require knowledge of FFI.

## Usage

Expand Down
3 changes: 3 additions & 0 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ const ERROR_TOO_MANY_SEM_REQUESTS = 103;
/// Cannot request exclusive semaphores at interrupt time.
const ERROR_INVALID_AT_INTERRUPT_TIME = 104;

/// The service has not been started.
const ERROR_SERVICE_NOT_ACTIVE = 1026;

/// The device is not connected.
const ERROR_DEVICE_NOT_CONNECTED = 1167;

Expand Down
38 changes: 38 additions & 0 deletions lib/src/constants_winsock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,41 @@ const FD_OOB = 0x04;
const FD_ACCEPT = 0x08;
const FD_CONNECT = 0x10;
const FD_CLOSE = 0x20;

// Address formats
const AF_UNSPEC = 0;
const AF_UNIX = 1;
const AF_INET = 2;
const AF_IMPLINK = 3;
const AF_PUP = 4;
const AF_CHAOS = 5;
const AF_NS = 6;
const AF_IPX = AF_NS;
const AF_ISO = 7;
const AF_OSI = AF_ISO;
const AF_ECMA = 8;
const AF_DATAKIT = 9;
const AF_CCITT = 10;
const AF_SNA = 11;
const AF_DECnet = 12;
const AF_DLI = 13;
const AF_LAT = 14;
const AF_HYLINK = 15;
const AF_APPLETALK = 16;
const AF_NETBIOS = 17;
const AF_VOICEVIEW = 18;
const AF_FIREFOX = 19;
const AF_UNKNOWN1 = 20;
const AF_BAN = 21;
const AF_ATM = 22;
const AF_INET6 = 23;
const AF_CLUSTER = 24;
const AF_12844 = 25;
const AF_IRDA = 26;
const AF_NETDES = 28;
const AF_TCNPROCESS = 29;
const AF_TCNMESSAGE = 30;
const AF_ICLFXBM = 31;
const AF_BTH = 32;
const AF_LINK = 33;
const AF_HYPERV = 34;
21 changes: 21 additions & 0 deletions lib/src/win32/iphlpapi.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ final _AddIPAddress = _iphlpapi.lookupFunction<
Pointer<Uint32> NTEContext,
Pointer<Uint32> NTEInstance)>('AddIPAddress');

/// The ConvertInterfaceGuidToLuid function converts a globally unique
/// identifier (GUID) for a network interface to the locally unique
/// identifier (LUID) for the interface.
///
/// ```c
/// ConvertInterfaceGuidToLuid(
/// [in] const GUID *InterfaceGuid,
/// [out] PNET_LUID InterfaceLuid
/// );
/// ```
/// {@category iphlpapi}
int ConvertInterfaceGuidToLuid(
Pointer<GUID> InterfaceGuid, Pointer<NET_LUID_LH> InterfaceLuid) =>
_ConvertInterfaceGuidToLuid(InterfaceGuid, InterfaceLuid);

final _ConvertInterfaceGuidToLuid = _iphlpapi.lookupFunction<
Int32 Function(
Pointer<GUID> InterfaceGuid, Pointer<NET_LUID_LH> InterfaceLuid),
int Function(Pointer<GUID> InterfaceGuid,
Pointer<NET_LUID_LH> InterfaceLuid)>('ConvertInterfaceGuidToLuid');

/// The DeleteIPAddress function deletes an IP address previously added
/// using AddIPAddress.
///
Expand Down
22 changes: 22 additions & 0 deletions lib/src/win32/ws2_32.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,28 @@ Pointer<Utf8> inet_ntoa(IN_ADDR in_) => _inet_ntoa(in_);
final _inet_ntoa = _ws2_32.lookupFunction<Pointer<Utf8> Function(IN_ADDR in_),
Pointer<Utf8> Function(IN_ADDR in_)>('inet_ntoa');

/// The inet_ntop function converts an IPv4 or IPv6 Internet network address
/// into a string in Internet standard format.
///
/// ```c
/// PCSTR WSAAPI inet_ntop(
/// [in] INT Family,
/// [in] const VOID *pAddr,
/// [out] PSTR pStringBuf,
/// [in] size_t StringBufSize
/// );
/// ```
/// {@category winsock}
Pointer<Utf8> inet_ntop(int Family, Pointer pAddr, Pointer<Utf8> pStringBuf,
int StringBufSize) =>
_inet_ntop(Family, pAddr, pStringBuf, StringBufSize);

final _inet_ntop = _ws2_32.lookupFunction<
Pointer<Utf8> Function(Int32 Family, Pointer pAddr,
Pointer<Utf8> pStringBuf, IntPtr StringBufSize),
Pointer<Utf8> Function(int Family, Pointer pAddr, Pointer<Utf8> pStringBuf,
int StringBufSize)>('inet_ntop');

/// The ioctlsocket function controls the I/O mode of a socket.
///
/// ```c
Expand Down
5 changes: 5 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ homepage: https://win32.pub
repository: https://github.com/timsneath/win32
issue_tracker: https://github.com/timsneath/win32/issues

topics:
- win32
- windows
- ffi

environment:
sdk: '>=2.17.0 <4.0.0'

Expand Down
22 changes: 22 additions & 0 deletions test/api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,17 @@ void main() {
expect(inet_ntoa, isA<Function>());
});
}
if (windowsBuildNumber >= 9600) {
test('Can instantiate inet_ntop', () {
final ws2_32 = DynamicLibrary.open('ws2_32.dll');
final inet_ntop = ws2_32.lookupFunction<
Pointer<Utf8> Function(Int32 Family, Pointer pAddr,
Pointer<Utf8> pStringBuf, IntPtr StringBufSize),
Pointer<Utf8> Function(int Family, Pointer pAddr,
Pointer<Utf8> pStringBuf, int StringBufSize)>('inet_ntop');
expect(inet_ntop, isA<Function>());
});
}
if (windowsBuildNumber >= 9600) {
test('Can instantiate ioctlsocket', () {
final ws2_32 = DynamicLibrary.open('ws2_32.dll');
Expand Down Expand Up @@ -8776,6 +8787,17 @@ void main() {
Pointer<Uint32> NTEInstance)>('AddIPAddress');
expect(AddIPAddress, isA<Function>());
});
test('Can instantiate ConvertInterfaceGuidToLuid', () {
final iphlpapi = DynamicLibrary.open('iphlpapi.dll');
final ConvertInterfaceGuidToLuid = iphlpapi.lookupFunction<
Int32 Function(
Pointer<GUID> InterfaceGuid, Pointer<NET_LUID_LH> InterfaceLuid),
int Function(
Pointer<GUID> InterfaceGuid,
Pointer<NET_LUID_LH>
InterfaceLuid)>('ConvertInterfaceGuidToLuid');
expect(ConvertInterfaceGuidToLuid, isA<Function>());
});
test('Can instantiate DeleteIPAddress', () {
final iphlpapi = DynamicLibrary.open('iphlpapi.dll');
final DeleteIPAddress = iphlpapi.lookupFunction<
Expand Down
10 changes: 10 additions & 0 deletions tool/win32gen/data/win32_functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,10 @@
"prototype": "BOOL ContinueDebugEvent(\n DWORD dwProcessId,\n DWORD dwThreadId,\n DWORD dwContinueStatus\n);",
"comment": "Enables a debugger to continue a thread that previously reported a debugging event."
},
"ConvertInterfaceGuidToLuid": {
"prototype": "ConvertInterfaceGuidToLuid(\n [in] const GUID *InterfaceGuid,\n [out] PNET_LUID InterfaceLuid\n);",
"comment": "The ConvertInterfaceGuidToLuid function converts a globally unique identifier (GUID) for a network interface to the locally unique identifier (LUID) for the interface."
},
"CopyAcceleratorTable": {
"prototype": "int CopyAcceleratorTableW(\n HACCEL hAccelSrc,\n LPACCEL lpAccelDst,\n int cAccelEntries\n);",
"comment": "Copies the specified accelerator table. This function is used to obtain the accelerator-table data that corresponds to an accelerator-table handle, or to determine the size of the accelerator-table data."
Expand Down Expand Up @@ -3007,6 +3011,12 @@
"category": "winsock",
"minimumWindowsVersion": "WIN81"
},
"inet_ntop": {
"prototype": "PCSTR WSAAPI inet_ntop(\n [in] INT Family,\n [in] const VOID *pAddr,\n [out] PSTR pStringBuf,\n [in] size_t StringBufSize\n);",
"comment": "The inet_ntop function converts an IPv4 or IPv6 Internet network address into a string in Internet standard format.",
"category": "winsock",
"minimumWindowsVersion": "WIN81"
},
"InflateRect": {
"prototype": "BOOL InflateRect(\n LPRECT lprc,\n int dx,\n int dy\n);",
"comment": "The InflateRect function increases or decreases the width and height of the specified rectangle. The InflateRect function adds -dx units to the left end and dx to the right end of the rectangle and -dy units to the top and dy to the bottom. The dx and dy parameters are signed values; positive values increase the width and height, and negative values decrease them."
Expand Down

0 comments on commit 61efad5

Please sign in to comment.