<div dir="ltr"><div><div><div><div>Thanks Even,<br><br></div>This seems to be working. But unfortunately we have projection code in several places, like<br><a href="https://mapwingis.codeplex.com/SourceControl/latest#MapWinGIS/trunk/Processing/Projections.cpp">https://mapwingis.codeplex.com/SourceControl/latest#MapWinGIS/trunk/Processing/Projections.cpp</a> and<br>

<a href="https://mapwingis.codeplex.com/SourceControl/latest#MapWinGIS/trunk/Grid/tkGridRaster.cpp">https://mapwingis.codeplex.com/SourceControl/latest#MapWinGIS/trunk/Grid/tkGridRaster.cpp</a> (around like 440).<br><br>
</div>
I tried to use your suggestion in all those places, but it does compile but doesn't run.<br></div>I'll need to let a true C++ developer look at it ;)<br><br></div>Thanks,<br></div><div class="gmail_extra"><br clear="all">

<div><br>
<br>
Paul<br>
<br>
<div style="font-size:13.3px;font-family:Verdana,Arial,Helvetica,sans-serif"><div style="border:1px solid #e5e5e5;background-color:#f8f8f8;padding:0.8em 0.8em 0.3em 0.8em"><div style="margin:0 0 8px 0"><p style="margin:0">

<span><b><img style="float:left;margin-left:5px;margin-right:5px" src="http://www.bontepaarden.nl/bontepaarden/images/newButton.png" alt="" height="120" width="160">Paul Meems </b><br><span>Release manager, configuration manager</span><br>

<span>and forum moderator of MapWindow GIS.</span><br><a href="http://www.mapwindow.org/" target="_blank"><span>www.mapwindow.org</span></a><br><br><span>Owner of MapWindow.nl - Support for</span><br><span>Dutch speaking users.</span><br>

<a href="http://www.mapwindow.nl/" target="_blank"><span>www.mapwindow.nl</span></a><br></span></p>
<p style="margin:0"><b><br></b></p></div></div><img src="http://p1.wisestamp.com/pixel.png?p=mozilla&v=3.9.12&t=1322134056890&u=482737fd0c4ca423" height="1" width="1"></div>
</div>
<br><br><div class="gmail_quote">2014-01-26 Even Rouault <span dir="ltr"><<a href="mailto:even.rouault@mines-paris.org" target="_blank">even.rouault@mines-paris.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Le samedi 25 janvier 2014 23:50:10, Paul Meems a écrit :<br>
<div><div class="h5">> Hi all,<br>
><br>
> Thanks to Tamas Szekeres we are now using his binaries from<br>
> <a href="http://www.gisinternals.com/sdk/" target="_blank">http://www.gisinternals.com/sdk/</a> with MapWinGIS, our mapping ActiveX.<br>
> This has drastically simplified our build process and we are very grateful<br>
> for Tamas' help.<br>
><br>
> We're now struggling with some minor issues regarding our 'old' C++ code<br>
> and the new binaries for GDAL, GEOS, Proj4, etc.<br>
> Several of them I managed to solve, but I'm struggling with this one.<br>
> We have code to read a prj file and get the Proj4 string:<br>
><br>
>     void ProjectionTools::GetProj4FromPRJFile(char * prjfileName, char **<br>
> prj4)<br>
>     {<br>
>         FILE * pFile;<br>
>         pFile = fopen (prjfileName,"r");<br>
>         if (pFile == NULL)<br>
>         {<br>
>             // Doesn't exist<br>
>             return;<br>
>         }<br>
>         fclose(pFile);<br>
>         pFile = NULL;<br>
>         OGRSpatialReference* oSRS = new OGRSpatialReference();<br>
><br>
>         char **papszPrj = CSLLoad(prjfileName);<br>
>         if (papszPrj == NULL)<br>
>         {<br>
>             return;<br>
>         }<br>
><br>
>         OGRErr eErr = oSRS->importFromESRI(papszPrj);<br>
>         if (eErr != OGRERR_NONE)<br>
>         {<br>
>             OGRErr eErr = oSRS->importFromProj4(*papszPrj);<br>
>         }<br>
><br>
>         CSLDestroy( papszPrj );<br>
>         char * pszProj4 = NULL;<br>
>         eErr = oSRS->exportToProj4( &pszProj4 );<br>
>         delete oSRS; <-- going wrong now<br>
><br>
>         *prj4 = new char[_tcslen(pszProj4)+1];<br>
>         strcpy(*prj4, pszProj4);<br>
>         CPLFree(pszProj4);<br>
>     }<br>
><br>
> This code was working for years, but now it crashes on delete oSRS;.<br>
> I've been searching for examples of how to use exportToProj4() in C++ but<br>
> can only find Python examples.<br>
> And I'm not a C++ developer, just a C# developer :)<br>
> How should I now free oSRS?<br>
<br>
</div></div>The code looks OK and there's no fundamental reason why it would not work any<br>
longer. I highly suspect that you are running into a classical issue of a<br>
mismatch between the compile flags used in your application and the ones used<br>
by the GDAL built itself.<br>
<br>
You could perhaps avoid that by letting GDAL do the allocation and<br>
deallocation with<br>
<br>
oSRS = (OGRSpatialReference*)OSRNewSpatialReference(NULL);<br>
<br>
and<br>
<br>
OGRSpatialReference::DestroySpatialReference(oSRS)<br>
<div class="im"><br>
><br>
> Thanks for any advice.<br>
><br>
> Paul<br>
><br>
</div>> *Paul Meems *<br>
<div class="HOEnZb"><div class="h5">> Release manager, configuration manager<br>
> and forum moderator of MapWindow GIS.<br>
> <a href="http://www.mapwindow.org" target="_blank">www.mapwindow.org</a><br>
><br>
> Owner of MapWindow.nl - Support for<br>
> Dutch speaking users.<br>
> <a href="http://www.mapwindow.nl" target="_blank">www.mapwindow.nl</a><br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Geospatial professional services<br>
<a href="http://even.rouault.free.fr/services.html" target="_blank">http://even.rouault.free.fr/services.html</a><br>
</font></span></blockquote></div><br></div>