Note that there are some explanatory texts on larger screens.

plurals
  1. POPinvoke struct marshalling help needed - System.AccessViolationException
    primarykey
    data
    text
    <p>Hey! I've just begun fiddling with pinvoke and have encountered a problem. I'm getting the AccessViolationException. First of all, is there some way to debug or trace out which field is causing this error? The only thing being written to is the result struct.</p> <p>The c++ call looks like:</p> <pre><code>MyFunc(int var1, _tuchar *var2, _tuchar *var3, _tuchar *var4, MyStruct *Result, _tuchar *var5, _tuchar *var6); </code></pre> <p>The c++ struct:</p> <pre><code>typedef struct MyStruct { _tuchar *id; _tuchar *ErrorMessages; int int1; _tuchar language[3]; _tuchar *result; int type; int number; int *type2; _tuchar **blocks; } </code></pre> <p>The C# struct:</p> <pre><code>[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct MyStruct { [MarshalAs(UnmanagedType.LPStr)] public string Id; [MarshalAs(UnmanagedType.ByValArray, SizeConst=500)] public char[] ErrorMessages; public int int1; [MarshalAs(UnmanagedType.LPStr)] public string language; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)] public char[] result; public int type; public int number; public int type2; [MarshalAs(UnmanagedType.ByValArray)] public string[] blocks; </code></pre> <p>The C# method declaration:</p> <pre><code>[DllImport(MyPath, EntryPoint = "MyEntryPoint", SetLastError = true, CharSet = CharSet.Unicode)] internal static extern int MyFunc(int var1, string var2, string var3, string var4, ref MyStruct Result, string var5, string var6); </code></pre> <p>The C# Call:</p> <pre><code>var result = new MyStruct(); MyFunc(0, "var2", "var3", "var4", ref result, "var5", "var6"); </code></pre> <p>Hope I haven't left anything out. Thanks for any help!</p>
    singulars
    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