dna 0.0.2 copy "dna: ^0.0.2" to clipboard
dna: ^0.0.2 copied to clipboard

outdatedDart 1 only

Dart Native Access.

DNA #

Dart Native Access

Usage #

Linux #

libc library

@Lib('libc.so.6')
class Libc {
  dynamic lib = new DynamicLibrary<Libc>();

  int getpid() { return lib.getpid(); }
  int getuid() { return lib.getuid(); }
  int getgroups (int count, @Arg(ARG_LISTINT) Ref<List<int>> groups) { return lib.getgroups(count, groups); }

  int rand() { return lib.rand(); }
  int rand_r(@Arg(ARG_POINTER) seedp) { return lib.rand_r(seedp); }
  void srand(@Arg(ARG_INT) int seed) { return lib.srand(seed); }
}

void main(){
  Libc libc = new Libc();
  var processId = libc.getpid();
  print('pid $processId = ${io.pid}');

  var userId = libc.getuid();
  print('userId ${userId}');

  libc.srand(123456789);
  var rand = libc.rand();
  print('rand $rand');

  Ref<int> seed = new Ref<int>(123456789);
  var srand = libc.rand_r(seed);
  print('srand $srand');

}

Windows #

kenel32 library

@Lib('Kernel32.dll')
class Kernel32 {
  dynamic lib = new DynamicLibrary<Kernel32>();

  int GetCurrentProcess() { return lib.GetCurrentProcess(); }
  int GetProcessId(@Arg(ARG_INT) int process) { return lib.GetProcessId(process); }
  int GetModuleFileNameA(@Arg(ARG_INT) int process, @Arg(ARG_STRING) Ref<String> imageFileName, @Arg(ARG_INT) int size)  { return lib.GetModuleFileNameA(process, imageFileName, size); }
  bool GetProcessWorkingSetSize(@Arg(ARG_INT) int process, @Arg(ARG_POINTER) Ref<int> minimumWorkingSetSize, @Arg(ARG_POINTER) Ref<int> maximumWorkingSetSize) { return lib.GetProcessWorkingSetSize(process, minimumWorkingSetSize, maximumWorkingSetSize); }

  int GetLastError() { return lib.GetLastError(); }
}

void main(){
  Kernel32 kernel32 = new Kernel32();
  var process = kernel32.GetCurrentProcess();
  var processId = kernel32.GetProcessId(process);
  print('pid $processId = ${io.pid}');

  Ref<int> min = new Ref<int>(0);
  Ref<int> max = new Ref<int>(0);
  var result = kernel32.GetProcessWorkingSetSize(process, min, max);
  print('min ${min.value} max ${max.value} result $result error ${kernel32.GetLastError()}');

  Ref<String> nameRef = new Ref<String>(Strings.fill(' ', 64));
  result = kernel32.GetModuleFileNameA(0, nameRef, nameRef.value.length);
  print('${nameRef.value} result $result error ${kernel32.GetLastError()}');

}

Requirements #

Linux 64-bit Windows 32-bit and 64-bit

2
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Dart Native Access.

Homepage

License

unknown (LICENSE)

More

Packages that depend on dna