title: P/Invoking function via a mangled name
body: <p>I'm trying to call an function in an unmanaged c++ dll in .net cf 3.5 in a windows ce 6.0 environment.</p>
  
  <p>The struct is defined as:</p>
  
  <pre><code>typedef struct TagOperatorInfo
  {
      DWORD dwMode;       
      DWORD dwFormat;     //Operator name format
      DWORD dwAct;        //Network type(Available in 3G module£ºGSM or 3G),
      TCHAR szOper[32];   
  }OperatorInfo,*LPOperatorInfo;
  </code></pre>
  
  <p>and the function call is:</p>
  
  <pre><code>BOOL GetCurOperatorInfo(LPOperatorInfo pinfo);
  </code></pre>
  
  <p>I defined in .net the TagOperatorInfo  as follows:</p>
  
  <pre><code>[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
      public struct TagOperatorInfo
      {
  
          /// DWORD-&gt;unsigned int
          public uint dwMode;
  
          /// DWORD-&gt;unsigned int
          public uint dwFormat;
  
          /// DWORD-&gt;unsigned int
          public uint dwAct;
  
          /// TCHAR[32]
          [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst = 32)]
          public string szOper;
      }
  </code></pre>
  
  <p>and after seeing some articles and msdn documentation i call the native function as:</p>
  
  <pre><code>[System.Runtime.InteropServices.DllImportAttribute(gsmaAdapterDLLName, EntryPoint = "#30", CallingConvention = CallingConvention.Winapi)]
      [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
      internal static extern bool GetCurOperatorInfo([MarshalAs(UnmanagedType.LPStruct)] ref NativeHelper.TagOperatorInfo operatorInfo);
  </code></pre>
  
  <p>Note: I call the function with an entry point defined with the ordinal because the c++ mangled names.</p>
  
  <p>The problem that i have is that i always get the notSupportedException throw. I don't understand because the ref parameter should give it the Pointer to the struct.</p>
  
  <p>My .net function that calls it is:</p>
  
  <pre><code>/// &lt;summary&gt;
      /// Gets the current operator information.
      /// &lt;/summary&gt;
      /// &lt;param name="operatorInfo"&gt;The operator info.&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public static bool GetOperatorInformation(out NativeHelper.TagOperatorInfo operatorInfo)
      {
          operatorInfo = new NativeHelper.TagOperatorInfo();
  
          if (NativeImports.GetCurOperatorInfo(ref operatorInfo) == true)
          {
              return true;
          }
          else
          {
              return false;
          }
  
      }
  </code></pre>
  
  <p>What i'm missing for this to work.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>New <em>.Net Compact Framework</em> method call</p>
  
  <pre><code>[System.Runtime.InteropServices.DllImportAttribute(gsmaAdapterDLLName, EntryPoint = "?GetCurOperatorInfo@CGSMAdapter@@YAHPAUTagOperatorInfo@@@Z", CallingConvention = CallingConvention.Winapi)]
      [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
      internal static extern bool GetCurOperatorInfo([MarshalAs(UnmanagedType.LPStruct)]ref NativeHelper.TagOperatorInfo operatorInfo);
  </code></pre>