I have a problem while using the optional and defaultvalue MIDL attributes
in a method declaration.
Here is my sample MIDL method declaration
HRESULT Add ( [in] int a, [in] int b, [in, optional, defaultvalue(10)] int c)
I have written a COM client by importing the typelibrary of the above IDL
but while calling the Add method from the client it ask me to give all the
three parameters eventhough i declared the third parameter as optional value
but if i use the ".h" and "_i.c" files the compiler accepting two arguments.
May i know why this discrepencey?
can i get the optional attribute feature whil imporing the tlb file also?
please suggest me a way to use optional parameters by imporing the tlbs in
the client side code
this same code is working fin in VB.
Waiting for your response
> HRESULT Add ( [in] int a, [in] int b, [in, optional, defaultvalue(10)] int c)
> I have written a COM client by importing the typelibrary of the above IDL
> but while calling the Add method from the client it ask me to give all the
> three parameters eventhough i declared the third parameter as optional value
#import doesn't always carry over the optional and defaultvalue attributes. I believe it only does it for VARIANTs, though I haven't looked at it that carefully.
One option that might work for you is to make the last value a VARIANT instead, and then in your implementation check:
STDMETHODIMP CMyImpl::Add(..., VARIANT c)
int actualC = 10;
if (c.vt != VT_ERROR)
// Specify better flags if you care about locale conversions, etc.
hr = VariantChangeType(&c, &c, 0, VT_I4);
if (FAILED(hr)) return hr;
actualC = c.lVal;
// Work with actualC from here on
That should work with both VB and C++ clients.
"Vinoth Kumar.V.K" <Vinoth Kuma...@discussions.microsoft.com> wrote in