开发者

C++/CLI calling Interop wrapper methods with out parameters

I've got an Interop wrapper to some unmanaged DLL calls that return details through out paremeters. Th开发者_如何学运维e 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...


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜