2

I have an managed C++ Wrapper for unmanaged C++ code and it's necessary to use some pointer parameters into the methods!

What's the best way in C# to call this wrapper functions (I tryed it with reference parameter in the managed code and create the pointer and call then the unmanaged code)?

Example:

// c++/managed
Uint32 someMethod(int &value);

Uint32 Wrapper::someMethod(int &value)
{
    int *valuePtr = &value;
    return unmanagedObj->someMethod(valuePtr);
}

// c++/unmanaged
Uint32 someMethod(int *value);

Uint32 UnmanagedClass::someMethod(int *value)
{
    ...
}

I use the managed C++ wrapper with "add reference" in VS2008, but when I call someMethod in C# there are only a pointer instead of reference?!

// c#
// e.g. value conversion to C++ pointer
...
Wrapper wrapper = new Wrapper();
wrapper.someMethod(ref value); // should work but here we have an C++ pointer
// and not a reference ?!?!

Thank you for any tips!

greets

Xeo
  • 129,499
  • 52
  • 291
  • 397
leon22
  • 5,280
  • 19
  • 62
  • 100

1 Answers1

3

What you are looking for is int%, which is the correct syntax for C++CLI references and called a tracking reference:

Uint32 Wrapper::someMethod(int %value)
Xeo
  • 129,499
  • 52
  • 291
  • 397