Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessViolationException in PInvoke function call with double arrays and void pointers
    primarykey
    data
    text
    <p>I want to call two functions from a DLL with pure-C interface via PInvoke with the following signatures:</p> <pre><code>void *pj_init_plus(const char *srsName); int pj_datum_transform(void *src, void *dst, long point_count, int point_offset, double *x, double *y, double *z ); </code></pre> <p>Pinvoke methods:</p> <pre><code>[DllImport("proj.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "pj_init_plus", CharSet = CharSet.Ansi)] public static extern IntPtr PjInit(string srsName); [DllImport("proj.dll", EntryPoint = "pj_transform", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public static extern int PjTransformation(IntPtr src, IntPtr dst,long pointCount, int pointOffset, double[] x, double[] y,double[] z); </code></pre> <p>In my C#-code i call the methods:</p> <pre><code>IntPtr pjSrc = PjInit("+proj=longlat +datum=WGS84 +no_defs"); IntPtr pjDst = PjInit("+proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs"); double[] x = { 4489580.7, 4489580.7 }; double[] y = { 5320767.7, 5320767.7 }; double[] z = { 0.0, 0.0}; PjTransformation(pjSrc, pjDst, x.Length, 1, x, y, z); </code></pre> <p>The PjInit-call works fine and returns a valid pointer. But calling PjTransformation throws an AccessViolationException-Exception. I think there is a problem with the double arrays. In one post was mentioned, that a clr-array is already compatible with a native array and has not to be manually marshalled. I also tried it with the attribute [MarshalAs(UnmanagedType.LPArray)] for the double-arrays, but that didn't help. Or could the Exception come from the struct which is returned as a void pointers from the first function call. The problem is i don't know the type of the struct.</p> <p>The dll functions are ok, i tried it with native c-code and it worked. Also the parameter pointOffset could not cause the exception.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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