Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add an attribute to a return value in C++/CLI?

In C#, you can decorate function return values with attributes, as follows:

[return: MarshalAs(UnmanagedType.IUnknown)]
object LoadStuff();

My question is, how can I do this in C++/CLI? I have this:

[return: MarshalAs(UnmanagedType::IUnknown)]
Object^ LoadStuff();

but the compiler is erroring with 'return' : unknown attribute qualifier.

Is there an alternate syntax which I haven't been able to find?

like image 322
Orion Edwards Avatar asked Nov 20 '25 00:11

Orion Edwards


1 Answers

Use returnvalue instead of return

[returnvalue: MarshalAs(UnmanagedType::IUknown)]

The full list of attribute targets is available in section 28.2 of the C++/CLI spec (PDF)

like image 51
JaredPar Avatar answered Nov 22 '25 16:11

JaredPar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!