Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>EDIT: Fixed answer, see below.</p> <p>Really you need to know what oldFunction is going to be doing with pStuff. If pStuff is a pointer to some unmanaged data you can try wrapping the definition of m_pStuff with:</p> <pre><code>#pragma unmanaged void* m_pStuff #pragma managed </code></pre> <p>This will make the pointer unmanaged which can then be passed into unmanaged functions. Of course you will not be able to assign any managed objects to this pointer directly. </p> <p>Fundamentally unmanaged and managed pointers are not the same and can't be converted without some sort of glue code that copies the underlying data. Basically managed pointers point to the managed heap and since this is garbage collected the actual memory address they point to can change over time. Unmanaged pointers do not change the memory address without you explicitly doing so. </p> <p>Scratch that, you can't define unmanaged / managed inside a class definition. But this test code seems to work just fine:</p> <pre><code>// TestSol.cpp : main project file. #include "stdafx.h" using namespace System; #pragma unmanaged void oldFunction(void** pStuff) { return; } #pragma managed ref class Test { public: void* m_test; }; int main(array&lt;System::String ^&gt; ^args) { Console::WriteLine(L"Hello World"); Test^ test = gcnew Test(); void* pStuff = test-&gt;m_test; oldFunction(&amp;pStuff); test-&gt;m_test = pStuff; return 0; } </code></pre> <p>Here I copy the pointer out of the managed object first and then pass that in by to the oldFunction. Then I copy the result (probably updated by oldFunction) back into the managed object. Since the managed object is on the managed heap, the compiler won't let you pass a reference to the pointer contained in that object as it may move when the garbage collector runs.</p>
 

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