Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That error more than likely means that you have a marshaling problem. </p> <p>You don't show us what the <code>ErroneousWord</code> type is, but I assume it's some kind of class defined in your C++ code. My guess is that it's not being marshaled correctly to a .NET <code>object</code>.</p> <p>Considering that it's a pointer (or a pointer to a pointer), try changing that parameter to an <a href="http://msdn.microsoft.com/en-us/library/system.intptr.aspx" rel="nofollow"><code>IntPtr</code> type</a> to represent a pointer, instead. It shouldn't matter, since you're simply passing <code>NULL</code> for the argument anyway, easily represented using the static <a href="http://msdn.microsoft.com/en-us/library/system.intptr.zero.aspx" rel="nofollow"><code>IntPtr.Zero</code> field</a>.</p> <p>You probably also want to marshal <code>Output</code> the exact same way. If you change the parameter to an <code>IntPtr</code> type, you'll receive a pointer to a <code>TCHAR*</code>, which you can then pass to the other unmanaged functions however you see fit (e.g., to free it).</p> <p>Try the following code:</p> <pre><code>[ DllImport("dllName", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl) ] public static extern UInt32 Foo( string InputWord, out IntPtr Output, // change to IntPtr UInt32 Options, out IntPtr List, // change to IntPtr out UInt32 Count); IntPtr output; IntPtr dummyError = IntPtr.Zero; uint dummyCount = 0; uint x = 0; Foo(Text, out output, x | y, out dummyError, out dummyCount); </code></pre> <p>You might also need to use the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.allochglobal.aspx" rel="nofollow"><code>Marshal.AllocHGlobal</code> method</a> to allocate unmanaged memory from your process that is accessible to the C++ code. Make sure that if you do so, you also call the corresponding <a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.freehglobal.aspx" rel="nofollow"><code>Marshal.FreeHGlobal</code> method</a> to release the memory.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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