Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to forward declare a method in C++/CLI to match the signature of a "Managed Extensions for C++" method which takes a reference to a managed type
    primarykey
    data
    text
    <p>I'd like to call a method being compiled with <code>/clr:oldsyntax</code> (Managed Extensions for C++ syntax) from c++ code being compiled with <code>/clr</code> (C++/CLI). However, I'm having trouble forward declaring the method in C++/CLI such that it matches up to the "Managed Extensions for C++" signature.</p> <p>The declaration in the version using "Managed Extensions for C++" looks like:</p> <pre><code>void MangToUnMangDateTime(System::DateTime &amp; managedDT, tm&amp; unmangDT); </code></pre> <p><em>Note: The first parameter (managedDT) is the parameter of interest for this question.</em> This results in the following msil for the method (found using ildasm.exe):</p> <pre><code>.method assembly static void MangToUnMangDateTime(valuetype [mscorlib]System.DateTime&amp; modopt([mscorlib]System.Runtime.CompilerServices.IsImplicitlyDereferenced) managedDT, valuetype tm* modopt([mscorlib]System.Runtime.CompilerServices.IsImplicitlyDereferenced) unmangDT) cil managed </code></pre> <h2>First Attempt:</h2> <p>My first attempt to forward declare this method in C++/CLI looked like:</p> <pre><code>void MangToUnMangDateTime2(System::DateTime % managedDT, tm&amp; unmangDT); </code></pre> <p>which resulted in the following msil:</p> <pre><code>.method assembly static void MangToUnMangDateTime(valuetype [mscorlib]System.DateTime&amp; managedDT, valuetype tm* modopt([mscorlib]System.Runtime.CompilerServices.IsImplicitlyDereferenced) unmangDT) cil managed </code></pre> <p>which matches except for the additional modopt MSIL declarator included in the "Managed Extensions for C++" version:</p> <pre><code>modopt([mscorlib]System.Runtime.CompilerServices.IsImplicitlyDereferenced) </code></pre> <h2>Second Attempt</h2> <p>My second attempt to forward declare this method in C++/CLI looked like:</p> <pre><code>MangToUnMangDateTime(System::DateTime &amp; managedDT, tm&amp; unmangDT); </code></pre> <p><em>As a side note, I was surpised this compiled in C++/CLI since I expected it to want me to use the % syntax on a managed type.</em> This resulted in the following msil:</p> <pre><code>.method assembly static void MangToUnMangDateTime(valuetype [mscorlib]System.DateTime* modopt([mscorlib]System.Runtime.CompilerServices.IsImplicitlyDereferenced) managedDT, valuetype tm* modopt([mscorlib]System.Runtime.CompilerServices.IsImplicitlyDereferenced) unmangDT) cil managed </code></pre> <p>This one matches the modopt MSIL declarator, but is a pointer <code>*</code> instead of a reference <code>&amp;</code>.</p> <h2>Question:</h2> <p><strong>So, is there a way for me to forward declare this in C++/CLI to match the signature in the "Managed Extensions for C++" version?</strong> Perhaps via an attribute on the parameter?</p> <p><strong>Constraints</strong>: I do not want to modify the "Managed Extensions for C++" version. Clearly, if I modify the "Managed Extensions for C++" version to be passed by value (which it probably should have been in the first place):</p> <pre><code>void MangToUnMangDateTime(System::DateTime managedDT, tm&amp; unmangDT); </code></pre> <p>then I can get the signatures to match by using the same declaration in C++/CLI.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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