work on P/Invoke variant (untested)