Re: Is there any way to hack around C#'s lack of support for optional arguments?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



There's also a couple of functions for dealing with variants
(GetObjectForNativeVariant/GetNativeVariantForObject) which can be used to
similar effect.

Hope this helps,

Nick Hall

"Manny Vellon" <mvellon@xxxxxxxxxx> wrote in message
news:%23oBi789NFHA.2468@xxxxxxxxxxxxxxxxxxxxxxx
> This works fine for the int pointers, but there's also a VARIANT * in the
> interface that requires some special handling. For the ints, there's some
> functions in the Marshal class that lets you treat IntPtrs as memory
> addresses and lets you write values into them without using unsafe code.
>
> Thx.
>
> "Mattias Sjögren" <mattias.dont.want.spam@xxxxxxxx> wrote in message
> news:OYZmGCwNFHA.3512@xxxxxxxxxxxxxxxxxxxxxxx
>> >Is it totally fruitless to try to deal with optional arguments?
>> >Arguably,
>>>it's not even strictly an issue with arguments tagged as optional. I can
>>>imagine an interface that omits the OPTIONAL keyword but simply documents
>>>that NULL pointer values are acceptable. How can this condition (invalid
>>>references) be tested in C#?
>>
>> The only way I can think of is to modify the interop assembly and
>> change the parameter types to IntPtr or int*. If you for example
>> change the plFlags type to int* (forcing you to use unsafe code in C#)
>> you can then write
>>
>> if ( flags != null )
>> *flags = 123;
>>
>>
>>
>> Mattias
>>
>> --
>> Mattias Sjögren [MVP] mattias @ mvps.org
>> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
>> Please reply only to the newsgroup.
>
>


.



Relevant Pages