Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>C++/CLI introduces managed objects, for which the pointer token * should be replaced with a ^, and a 'new' should be replaced with 'gcnew', you don't need to delete these objects when you're done with them, they'll be garbage collected, [edit] managed classes have a <strong>ref</strong> keyword in their definition [/edit].</p> <p>Wrapping the C++ <strong>MyClass</strong> class in a C++/CLI wrapper class <strong>WrapperCLass</strong> could look something like this:</p> <pre><code>#include &lt;stdio.h&gt; class MyClass { public: void ShowStuff(const wchar_t *a) { wprintf(a); } }; public ref class WrapperClass { MyClass *wrapped; public: WrapperClass() { wrapped = new MyClass; } ~WrapperClass() { delete wrapped; } void ShowStuff(IntPtr string) { wrapped-&gt;ShowStuff((const wchar_t *)string.ToPointer()); } }; </code></pre> <p>If you generate a dll with this, you'll be able to use it as a reference in your C# project and you won't have to use the factory function mechanism. In C++/CLI are available, so <strong>const wchar_t *</strong> is as wel.</p> <p>To convert a <strong>System::String</strong> to a <strong>const wchar_t *</strong> you could use something like this:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Client { class Program { static void Main(string[] args) { WrapperClass w = new WrapperClass(); IntPtr tmp; w.ShowStuff(tmp = System.Runtime.InteropServices.Marshal.StringToHGlobalUni("Test")); System.Runtime.InteropServices.Marshal.FreeHGlobal(tmp); } } } </code></pre> <p>(There could very well be better ways to do this...)</p> <p>For your return type you'll have to do the conversion in your wrapper class. Make some .net collection, iterate through your vector, convert the wstring to a System::String, and add it to the .net collection, and return that.</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. This table or related slice is empty.
    1. 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