Different result with same code in VC/C#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<br/>
Hi,<br/>
<br/>
this code in VC++ return me correct result<br/>
<br/>
char proSrc[] = "+proj=cass +ellps=bessel +lat_0=43d1905.727"N"" +lon_0=11d1955.9583"E"" +towgs84[-104.1,-49.1,-9.9,0.971,-2.917,0.714,-11.68]";<br/>
char proDst[]="+proj=latlong +datum=WGS84 +towgs84[-104.1,-49.1,-9.9,0.971,-2.917,0.714,-11.68]";<br/>
<br/>
projUV space;<br/>
space.v = 150000;<br/>
space.u = -150000;<br/>
<br/>
projPJ projSrc = pj_init_plus(proSrc);<br/>
projPJ projDst = pj_init_plus(proDst); <br/>
<br/>
space=pj_inv(space, projSrc); <br/>
<br/>
double x=space.u;<br/>
double y=space.v; <br/>
double z=0;<br/>
<br/>
double ris = pj_transform(projSrc, projDst, 1, 0, &x, &y, &z);<br/>
<br/>
...now I have imported this code in C# as follow:<br/>
<br/>
unsafe class Program<br/>
{<br/>
public struct projUV<br/>
{<br/>
public double u;<br/>
public double v;<br/>
}<br/>
<br/>
[DllImport(@"C:UserstDesktopLibproj.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "pj_init_plus")]<br/>
static extern void* pj_init_plus(string m);<br/>
<br/>
[DllImport(@"C:UserstDesktopLibproj.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto, EntryPoint = "pj_inv")]<br/>
static extern projUV pj_inv(projUV px, void* py);<br/>
<br/>
[DllImport(@"C:UserstDesktopLibproj.dll", EntryPoint = "pj_transform", CallingConvention = CallingConvention.Cdecl)]<br/>
static extern int pj_transform(void* src, void* dst, long point_count, int point_offset,
double* x, double* y, double* z);<br/>
<br/>
static void Main(string[] args)<br/>
{<br/>
<br/>
string proSrc = @"+proj=cass +ellps=bessel +lat_0=43d1905.727""N +lon_0=11d1955.9583""E";<br/>
<br/>
string proDst="+proj=latlong +datum=WGS84 +towgs84[-104.1,-49.1,-9.9,0.971,-2.917,0.714,-11.68]";<br/>
<br/>
void* projSrc = pj_init_plus(proSrc);<br/>
void* projDst = pj_init_plus(proDst);<br/>
<br/>
projUV space;<br/>
space.v = 15000;<br/>
space.u = -15000;<br/>
<br/>
space = pj_inv(space, projSrc);<br/>
<br/>
double x = space.u;<br/>
double y = space.v;<br/>
double z = 0.0;<br/>
<br/>
double ris = pj_transform(projSrc, projDst, 1, 0, &x, &y, &z);<br/>
<br/>
}<br/>
}<br/>
<br/>
but now last called function "ris = pj_transform(projSrc, projDst, 1, 0, &x, &y, &z);" return me an error:Attempted to read or write protected memory. This is often an indication that other memory is corrupt.<br/>
<br/>
I think that marshalling of string passed in pj_init_plus(proSrc) maybe the cause of problem but I dont understand how solve...<br/>
<br/>
anyone can help me?<br/>
<br/>
Thanks in advance,<br/>
<br/>
Guton<br/>
<br/>
this is the procedure prototypes<br/>
<br/>
projLP pj_inv(projXY, projPJ);<br/>
int pj_transform( projPJ src, projPJ dst, long point_count, int point_offset,<br/>
double *x, double *y, double *z );<br/>
<br/>
projPJ pj_init_plus(const char *);<br/>
<br/>
<br/>
p.s. sorry for my english<br/>
<br/>
<br/>



View the full article
 
Back
Top