Note that there are some explanatory texts on larger screens.

plurals
  1. POdllimport : c code affect a struct passed by reference (c#)
    primarykey
    data
    text
    <p>I've got a c dll that contains an exposed function, that takes three parameters : </p> <pre><code>int ParseInput(char* opt_path, char* input, SENNA_RESULT_ARRAY* result); </code></pre> <p>I want to call this from C#, which actually works. The problem is that the result struct is not affected. Here is the structure defined in c code : </p> <pre><code> typedef struct RESULT_ { char* word; int pos_start; int pos_end; char* pos; char* chk; char* ner; char* psg; } RESULT; typedef struct RESULT_ARRAY_ { int size; RESULT* Results; } RESULT_ARRAY; </code></pre> <p>and my c# code : </p> <pre><code>[StructLayout(LayoutKind.Sequential)] public struct SENNA_RESULT { [MarshalAs(UnmanagedType.LPStr)] public string word; [MarshalAs(UnmanagedType.I4)] public int pos_start; [MarshalAs(UnmanagedType.I4)] public int pos_end; [MarshalAs(UnmanagedType.LPStr)] public string pos; [MarshalAs(UnmanagedType.LPStr)] public string chk; [MarshalAs(UnmanagedType.LPStr)] public string ner; [MarshalAs(UnmanagedType.LPStr)] public string psg; } [StructLayout(LayoutKind.Sequential)] public struct SENNA_RESULT_ARRAY { public SENNA_RESULT[] Results; public int size; } [DllImport("Senna-32.dll", CharSet = CharSet.Ansi)] static extern int Parse(string msg, string stream, ref SENNA_RESULT_ARRAY results); Parse(@"path", "sentence", ref result_array) </code></pre> <p>I've tried many things, like : 1-use classes instead of struct without ref keyword 2-use a pointer instead of passing a struct</p> <p>Each time i got a different error like array is not of the specified type low level error( corrupted heap)</p> <p>even if i don't specify the array in the first struct, the size member has not the correct value (the C code prints the value in the console)</p> <p>Any advice ?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    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.
    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