I'm trying to get currently active application's name on windows flutter app using pid. Is there any way to get the app's name by process id? Here is my code:
import 'dart:ffi' as ffi;
import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart' as win;
void main(){
ffi.Pointer<ffi.Uint32> pidPointer = calloc();
int hwnd = win.GetForegroundWindow();
win.GetWindowThreadProcessId(hwnd, pidPointer);
int pid = pidPointer.value;
print('Process ID of the active window: $pid');
win.free(pidPointer);
}
Here is the solution: