-1

I've got an Interop wrapper to some unmanaged DLL calls that return details through out paremeters. The functions appear like this:

_myWrapper->My_Method( ... out UInt32 value ... );

So assuming the method is declared like this:

void My_Method(out UInt32 value);

How do I then call this method from within my C++/CLI code? I know how to call reference methods such as this easy enough:

void Another_Method(ref UInt32 value);

UInt32 _value;
_myWrapper->Another_Method(%_value);

I'm doing a little reading and I am reading it can't be done? I don't believe it... Likely this isn't impossible to overcome or workaround, but you've got to be kidding me? Is that really true?

Thank you...

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Michael
  • 57
  • 1
  • 7
  • What does `out UInt32 value` mean in the context of unmanaged code? I.e., what is `out` in C/C++? – ildjarn Sep 29 '11 at 15:46

1 Answers1

4

In C++, there's no special call syntax for calling a function with a reference parameter, you just write the call like it was pass-by-value. Of course, you need to supply an lvalue to be overwritten, the rvalue (temporary) result of an arithmetic expression can't be used.

BTW, your code for calling a ref function is wrong too, that might be the source of your troubles.

Example:

C# definition:

 void MySharpRef(ref int i)  { i = 4; }
 void MySharpOut(out int i)  { i = 5; }

C++/CLI definition:

 void MyPlusRef(System::Int32% i) { i = 14; }
 void MyPlusOut([System::Runtime::InteropServices::OutAttribute] System::Int32% i) { i = 15; }

C# call:

 int j;
 o.MyPlusOut(out j);
 o.MyPlusRef(ref j);

C++/CLI call:

 System::Int32 k;
 p->MySharpOut(k);
 p->MySharpRef(k);
ildjarn
  • 62,044
  • 9
  • 127
  • 211
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720