use managed c++ instead of pinvoke