Skip to content

Commit 9926f85

Browse files
committed
FlatBuffers wrapper - fix windows - missing DynamicLibrary.process()
1 parent ae5a61a commit 9926f85

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/src/bindings/flatbuffers.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:typed_data';
22

33
import 'package:ffi/ffi.dart' as f;
44
import 'dart:ffi';
5+
import 'dart:io' show Platform;
56

67
import '../../flatbuffers/flat_buffers.dart' as fb;
78

@@ -69,8 +70,17 @@ class _Allocator extends fb.Allocator {
6970

7071
@override
7172
void clear(ByteData data, bool _) {
72-
_memset ??= DynamicLibrary.process().lookupFunction<
73-
Void Function(Pointer<Void>, Int32, IntPtr), _dart_memset>('memset');
73+
if (_memset == null) {
74+
DynamicLibrary lib;
75+
if (Platform.isWindows) {
76+
// DynamicLibrary.process() is not available on Windows
77+
lib = DynamicLibrary.open('msvcr100.dll');
78+
} else {
79+
lib = DynamicLibrary.process();
80+
}
81+
_memset = lib.lookupFunction<Void Function(Pointer<Void>, Int32, IntPtr),
82+
_dart_memset>('memset');
83+
}
7484
_memset(_allocs[data].cast<Void>(), 0, data.lengthInBytes);
7585
}
7686
}

0 commit comments

Comments
 (0)