How to know is param is handle to object or object

  • Thread starter Thread starter Marko
  • Start date Start date
M

Marko

Hi,

There are few properties that don't follow the
traditional 'by handle' values.

For example:
System::Runtime::Serialization::Formatter ^f = ...;
System::Runtime::Serialization::StreamingContext ^c = ...;
f->Context = *c; (???)

Is there any way to figure if the param to the property
(or method) is 'handle' or class instance?

Does is mater if the ReturnType class is IsValueType?


Thanks.
 
Marko said:
There are few properties that don't follow the
traditional 'by handle' values.
Typically, you do use handles for reference types and
do not for value types. It's not directly related to
properties.
For example:
System::Runtime::Serialization::Formatter ^f = ...;
System::Runtime::Serialization::StreamingContext ^c = ...;
StreamingContext is a value type.
StreamingContext^ is a reference to the boxed version
of StreamingContext (in C# it would be object or
System.ValueType). C++/CLI provides type-safe access
to boxed value types.

You should use StreamingContext without the handle.
f->Context = *c; (???)

Is there any way to figure if the param to the property
(or method) is 'handle' or class instance?
MSDN Library uses C# terminology in the index
(structure is a value type, class is a reference type).
The about page in MSDN lists the declaration
(in C++/CLI: value class or ref class for value type or
reference type, respectively)

-hg
 
Holger said:
StreamingContext is a value type.
StreamingContext^ is a reference to the boxed version
of StreamingContext (in C# it would be object or
System.ValueType). C++/CLI provides type-safe access
to boxed value types.

You should use StreamingContext without the handle.

Yes, I figured that out that by myself.
Value types must be passed without a 'handle to object (^)'.

Also, the function pointers are always resolved as
System::IntPtr ^, but they can not be used as such directly.

For example, the PropetyInfo for the second param to EvantHandler method
constructor will return System::IntPtr,
but if you try to pass the IntPtr as a param to the constructor the
compiler will fail with:

error C3924: error in argument #2 of delegate constructor call
'System::EventHandler': pointer to member function expected.

No MSDN does not desribe C3924 at all, and how can on figure out
what the 'pointer to member function' should be?
 
Back
Top