"Attempted to read or write protected memory. This is often an indication that other memory is corru

Discussion in 'ASP .Net' started by humbleaptience, Feb 22, 2006.

  1. I'm migrating from 1.1 to 2.0. This code worked fine in 1.1 , but now
    it throws an exception.

    public static int LLtoUTM(int datumIn, int datumOut, double p_lat,
    double p_lon,ref double UTMNorthing,ref double UTMEasting,ref int
    UTMZone)
    {
    int errno;
    //This is the formula for calculating which Zone a point is in at a
    particular lat/long
    int ZoneNumber = Convert.ToInt32((p_lon + 180) / 6) + 1;
    double[] x = new double[1];
    double[] y = new double[1];
    double[] z = new double[1];
    y[0] = p_lat*proj_api.Proj.DEG_TO_RAD;
    x[0] = p_lon*proj_api.Proj.DEG_TO_RAD;
    z[0] = 0.0;
    IntPtr src0= proj_api.Proj.pj_init_plus("+proj_api.Proj=latlong
    +datum=NAD27");
    IntPtr src1 = proj_api.Proj.pj_init_plus("+proj_api.Proj=latlong
    +datum=NAD83");
    IntPtr dst0 = proj_api.Proj.pj_init_plus("+proj_api.Proj=utm +zone="
    + ZoneNumber + " +datum=NAD27");
    IntPtr dst1 = proj_api.Proj.pj_init_plus("+proj_api.Proj=utm +zone="
    + ZoneNumber + " +datum=NAD83");
    //This nice little bit of code below is designed to execute
    pj_transfrom (the proj_api.Proj lib all around function)
    //with the correct parameters so that a datumshift to the correct
    datum is included.
    if(datumIn==0)
    {
    if(datumOut==0)
    {
    errno = proj_api.Proj.pj_transform(src0, dst0, 1, 1, x, y,
    z);//NAD27-NAD83
    }
    else
    {
    errno = proj_api.Proj.pj_transform(src0, dst1, 1, 1, x, y,
    z);//NAD27-NAD27
    }
    }
    else
    {
    if(datumOut==0)
    {
    errno = proj_api.Proj.pj_transform(src1, dst0, 1, 1, x, y,
    z);//NAD83-NAD27
    }
    else
    {
    <!------- ERROR THROWN HERE --------!>
    errno = proj_api.Proj.pj_transform(src1, dst1, 1,
    1, x, y, z); //NAD83-NAD83
    }
    }

    proj_api.Proj.pj_free(dst1);
    proj_api.Proj.pj_free(src1);
    proj_api.Proj.pj_free(dst0);
    proj_api.Proj.pj_free(src0);
    UTMNorthing = y[0];
    UTMEasting = x[0];
    UTMZone = ZoneNumber;
    return errno;
    }

    pj_transform is a function in a C# wrapper of the Proj library.

    public static extern int pj_transform(IntPtr src, IntPtr dst,
    int point_count, int point_offset,
    [InAttribute, OutAttribute] double[] x,
    [InAttribute, OutAttribute] double[] y,
    [InAttribute, OutAttribute] double[] z);

    I assume it has something to do with assigning in-out attributes to
    arrays?

    Thanks!
    humbleaptience, Feb 22, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?am9obm55Rw==?=

    Attempted to read or write protected memory

    =?Utf-8?B?am9obm55Rw==?=, Apr 19, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,681
    =?Utf-8?B?am9obm55Rw==?=
    Apr 19, 2006
  2. Dhruba Bandopadhyay
    Replies:
    0
    Views:
    5,216
    Dhruba Bandopadhyay
    May 12, 2006
  3. darrel
    Replies:
    5
    Views:
    403
    darrel
    Jul 9, 2007
  4. Sudhan
    Replies:
    1
    Views:
    631
  5. Replies:
    0
    Views:
    5,283
Loading...

Share This Page