P/Invoke design fixes