Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 27th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Encoding from C   to C#
  2. extern "C" RETURNCHAR_API char* testString()
  3. {
  4.     return test;
  5. }
  6.        
  7. extern "C" RETURNCHAR_API char* __cdecl testString();
  8.        
  9. public static class ImportTest
  10.     {
  11.         [DllImport("ReturnChar.dll", EntryPoint = "testString", CallingConvention = CallingConvention.Cdecl)]
  12.         public static unsafe extern char* testString();
  13.     }
  14.     public partial class MainWindow : Window
  15.     {
  16.         public unsafe MainWindow()
  17.         {
  18.             InitializeComponent();
  19.             try
  20.             {
  21.  
  22.                 StringBuilder sb = new StringBuilder(new string(ImportTest.testString()));
  23.                 textBox1.Text = sb.ToString();
  24.             }
  25.             catch(Exception ex)
  26.             {
  27.                 MessageBox.Show(ex.Message);
  28.             }
  29.         }
  30.     }