Re: passing by reference from unmanaged c++ -> c++/CLI -> c#
I'd suggest you introduce a "shadow variable" for the parameter in your managed wrapper, pass in the variable as a tracking reference from your C# code (don't know the C# syntax for that, though), assign it to the shadow variable and then assign it back after calling the wrapped native function.
Somewhat like this:
Code:
// Test25.cpp: Hauptprojektdatei.
#include "stdafx.h"
using namespace System;
class A //unmnaged SDK class
{
public:
void Foo(int& i) { ++i; }
};
//managed c++ wrapper
public ref class A_Wrapper
{
public:
A_Wrapper() { _unmanaged = new A; }
~A_Wrapper() { delete _unmanaged; }
void Foo(int% i)
{
int wrapper_i = i;
_unmanaged->Foo(wrapper_i);
i = wrapper_i;
}
private:
A * _unmanaged;
};
int main(array<System::String ^> ^args)
{
A_Wrapper ^wrapper = gcnew A_Wrapper;
int i = 1;
wrapper->Foo(i);
Console::WriteLine(i); // Will print 2
Console::ReadLine();
return 0;
}
Please use code tags when posting code.
Also, there's no need to post your question twice. You probably did so because you didn't see the new thread showing up after submitting your post. However, posts by new members may be automatically placed in the "moderation queue" when submitted, and only become visible once a moderator manually has approved them. This explains the delay before your post actualy appeared.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.