Note that there are some explanatory texts on larger screens.

plurals
  1. POGeoTrans p/invoke wrapper NullReferenceException
    text
    copied!<p>I'm trying to expose methods I need to call from the GeoTrans c++ library but, am running into issues. Any help would be great!</p> <p>I have the following c++ file that i'm running nmake against to compile into a dll.</p> <pre><code>#include &lt;iostream&gt; #include "CoordinateConversionService.h" #include "CoordinateSystemParameters.h" #include "GeodeticParameters.h" #include "CoordinateTuple.h" #include "GeodeticCoordinates.h" #include "CartesianCoordinates.h" #include "Accuracy.h" #include "MGRSorUSNGCoordinates.h" #include "UTMParameters.h" #include "UTMCoordinates.h" #include "CoordinateType.h" #include "HeightType.h" #include "CoordinateConversionException.h" using MSP::CCS::Precision; int main(int argc, char **argv){} extern "C"__declspec(dllexport) void __stdcall convertGeodeticToGeocentric(const double lat,const double lon, const double height, double&amp; x, double&amp; y, double&amp; z) { MSP::CCS::CoordinateSystemParameters geocentricParameters(MSP::CCS::CoordinateType::geocentric); MSP::CCS::CoordinateConversionService ccs( "WGE", &amp;geodeticParameters, "WGE", &amp;geocentricParameters ); MSP::CCS::Accuracy sourceAccuracy; MSP::CCS::Accuracy targetAccuracy; MSP::CCS::GeodeticCoordinates sourceCoordinates(MSP::CCS::CoordinateType::geodetic, lon, lat, height); MSP::CCS::CartesianCoordinates targetCoordinates(MSP::CCS::CoordinateType::geocentric); ccs.convertSourceToTarget( &amp;sourceCoordinates, &amp;sourceAccuracy, targetCoordinates, targetAccuracy ); x = targetCoordinates.x(); y = targetCoordinates.y(); z = targetCoordinates.z(); } extern "C"__declspec(dllexport) void __stdcall convertGeocentricToGeodetic(const double x, const double y, const double z, double&amp; lat,double&amp; lon, double&amp; height) { MSP::CCS::CoordinateSystemParameters geocentricParameters(MSP::CCS::CoordinateType::geocentric); MSP::CCS::GeodeticParameters geodeticParameters(MSP::CCS::CoordinateType::geodetic, MSP::CCS::HeightType::ellipsoidHeight); MSP::CCS::CoordinateConversionService ccs( "WGE", &amp;geocentricParameters, "WGE", &amp;geodeticParameters ); MSP::CCS::Accuracy sourceAccuracy; MSP::CCS::Accuracy targetAccuracy; MSP::CCS::CartesianCoordinates sourceCoordinates(MSP::CCS::CoordinateType::geocentric, x, y, z); MSP::CCS::GeodeticCoordinates targetCoordinates; ccs.convertSourceToTarget( &amp;sourceCoordinates, &amp;sourceAccuracy, targetCoordinates, targetAccuracy ); lat = targetCoordinates.latitude(); lon = targetCoordinates.longitude(); height = targetCoordinates.height(); } extern "C"__declspec(dllexport) void __stdcall convertGeocentricToUTM(const double x, const double y, const double z, long&amp; zone, char&amp; hemisphere, double&amp; easting, double&amp; northing) { MSP::CCS::CoordinateSystemParameters geocentricParameters(MSP::CCS::CoordinateType::geocentric); MSP::CCS::UTMParameters utmParameters(MSP::CCS::CoordinateType::universalTransverseMercator, 1, 0); MSP::CCS::CoordinateConversionService ccs( "WGE", &amp;geocentricParameters, "WGE", &amp;utmParameters ); MSP::CCS::Accuracy sourceAccuracy; MSP::CCS::Accuracy targetAccuracy; MSP::CCS::CartesianCoordinates sourceCoordinates(MSP::CCS::CoordinateType::geocentric, x, y, z); MSP::CCS::UTMCoordinates targetCoordinates; ccs.convertSourceToTarget( &amp;sourceCoordinates, &amp;sourceAccuracy, targetCoordinates, targetAccuracy ); zone = targetCoordinates.zone(); hemisphere = targetCoordinates.hemisphere(); easting = targetCoordinates.easting(); northing = targetCoordinates.northing(); } extern "C"__declspec(dllexport) void __stdcall convertGeocentricToMGRS(const double x, const double y, const double z, char*&amp; mgrsString, Precision::Enum&amp; precision) { MSP::CCS::CoordinateSystemParameters geocentricParameters(MSP::CCS::CoordinateType::geocentric); MSP::CCS::CoordinateSystemParameters mgrsParameters(MSP::CCS::CoordinateType::militaryGridReferenceSystem); MSP::CCS::CoordinateConversionService ccs( "WGE", &amp;geocentricParameters, "WGE", &amp;mgrsParameters ); MSP::CCS::Accuracy sourceAccuracy; MSP::CCS::Accuracy targetAccuracy; MSP::CCS::CartesianCoordinates sourceCoordinates(MSP::CCS::CoordinateType::geocentric, x, y, z); MSP::CCS::MGRSorUSNGCoordinates targetCoordinates; ccs.convertSourceToTarget( &amp;sourceCoordinates, &amp;sourceAccuracy, targetCoordinates, targetAccuracy ); mgrsString = targetCoordinates.MGRSString(); precision = targetCoordinates.precision(); } </code></pre> <p>I then have the following p/invoke calls in my c# class..</p> <pre><code>[DllImport("CoordinateConversionWrapper.dll")] private static extern void convertGeodeticToGeocentric(double lat, double lon, double height, ref double x, ref double y, ref double z); [DllImport("CoordinateConversionWrapper.dll")] private static extern void convertGeocentricToMGRS(double x, double y, double z, ref char[] mgrsString, Precision precision); </code></pre> <p>Calling any of the above p/invoke methods results in a NullReferenceException. It seems like the issue is within the c++ code itself but, not being a c++ expert I'm not sure what the issue is...</p> <p>Please Help!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload