NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

By Value vs By Reference Types

In general, when marshaling method arguments, value types are marshaled to unmanaged code as a value on the stack whereas reference types are marshaled as pointers on the stack. Classes (except Object), Interfaces, Strings, and Arrays are all considered reference types and are therefore marshaled as pointers. For example,

Method arguments can also be passed by reference. For marshaling purposes, passing arguments by-reference simply adds a level of indirection to the unmanaged type. For example, a managed integer is marshaled as 4-byte value on the stack, while a by-reference integer is marshaled as a pointer to an integer on the stack. When a reference type is passed by reference, another level of indirection is added to the unmanaged signature. For example,

The following code shows some examples of how marshaling is effected by the use of ByRef parameters:

Mgd Signature: void Method(long i);
Unmgd Signature: void Method(long i);
Mgd Signature: void Method(ref long i);
Unmgd Signature: void Method(long *i);
Mgd Signature: void Method(Object o);
Unmgd Signature: void Method(VARIANT o);
Mgd Signature: void Method(ref Object v);
Unmgd Signature: void Method(VARIANT *v);
Mgd Signature: void Method(IList il );
Unmgd Signature: void Method(IList *il);
Mgd Signature: void Method(ByRefIList il );
Unmgd Signature: void Method(IList **il);
Mgd Signature: void Method(String s);
Unmgd Signature: void Method(char *s);
Mgd Signature: void Method(ByRefString s);
Unmgd Signature: void Method(char **s);
Mgd Signature: void Method([MarshalAs(UnmanagedType.Bstr)] String s);
Unmgd Signature: void Method(BStr s);
Mgd Signature: void Method(ByRef [MarshalAs(UnmanagedType.Bstr)] String s);
Unmgd Signature: void Method(BStr *s);