Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No, there isn't.</p> <p><a href="http://msdn.microsoft.com/en-us/library/aa446536.aspx">Microsoft documentation</a> specifies that:</p> <blockquote> <p>[...] the .NET Compact Framework <strong>only supports Unicode</strong>, and consequently only includes the CharSet.Unicode (and CharSet.Auto which equals Unicode) value, and does not support any of the clauses of the Declare statement. This means that the ExactSpelling property is also not supported. </p> <p>As a result, if your DLL function expects an ANSI string, <strong>you'll need to perform the conversion in the DLL, or convert the string to a byte array using the overloaded GetBytes method of the ASCIIEncoding class</strong>, before calling the function, since the .NET Compact Framework will always pass a pointer to the Unicode string. [...]</p> </blockquote> <p>The solution is:</p> <p><strong>Functions in the DLL</strong></p> <pre><code>int MARSHALMOBILEDLL_API testString(const char* value); const char* MARSHALMOBILEDLL_API testReturnString(const char* value); </code></pre> <p><strong>Wrapper</strong></p> <pre><code>[DllImport("marshalMobileDll.dll")] public static extern int testString(byte[] value); [DllImport("marshalMobileDll.dll")] public static extern System.IntPtr testReturnString(byte[] value); </code></pre> <p><strong>Calling Code</strong></p> <pre><code>string s1 = "1234567"; int v = Wrapper.testString( Encoding.ASCII.GetBytes(s1)); string s2 = "abcdef"; IntPtr ps3 = Wrapper.testReturnString(Encoding.ASCII.GetBytes(s2)); string s3 = IntPtrToString(ps3); private string IntPtrToString(IntPtr intPtr) { string retVal = ""; byte b = 0; int i = 0; while ((b = Marshal.ReadByte(intPtr, i++)) != 0) { retVal += Convert.ToChar(b); } return retVal; } </code></pre>
    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.
    3. VO
      singulars
      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