P/Invoke marshaling improvements