Passing optional object arguments from COM components 
Author Message
 Passing optional object arguments from COM components

Hello,

I have a dual interface COM component with a method that takes an
optional interface as one of its arguments, e.g. the IDL looks like

...
interface IFoo1 : IDispatch {
  HRESULT Open (
    [in] Mode Mode,
    [in, defaultvalue(NULL)] ITest* Test,
    [out, retval] IFoo2** Module );

Quote:
}

Calling this method from JScript with one argument results in a "Type
Mismatch" error.  I'm presuming that NULL gets transformed into a
variant that's not compatible with an IDispatch or IUnknown variant?
Dropping the defaultvalue modifier, and passing null as the second
argument produced the same error.  So is there any mechanism for
JScript to pass a null object pointer to a COM component, or am I
doomed to use variants explicitly here?  I'd like to avoid this if
possible as the component is also used by other languages.  I'd like to
preserve as much typing as I can at the IDL level, even if it gets
coerced to variants behind the scenes in JScript.

Thanks in advance for any help/suggestions,

Kevin Mitchell

Sent via Deja.com http://www.*-*-*.com/
Share what you know. Learn what you don't.



Sat, 08 Dec 2001 03:00:00 GMT  
 Passing optional object arguments from COM components
Solution 1. Use

interface IFoo1 : IDispatch {
  HRESULT Open (
    [in] Mode Mode,
    [in, defaultvalue(NULL)] IUknown* Test,
    [out, retval] IFoo2** Module );

Quote:
}

Then QI for ITest inside your IFoo1::Open implemetation. But it may not work with
early versions of Automation (OLEAUT32.DLL)

Solution 2. Works for sure, but more handwork:

interface IFoo1 : IDispatch {
  HRESULT Open (
    [in] Mode Mode,
    [in, optional] VARIANT* Test,
    [out, retval] IFoo2** Module );

Quote:
}

Then analyse Test by your own.

--
Regards,
Andrew Nosenko,
Senior Software Engineer
Mead & Company

Innovative browser extensions for weblications:
http://www.meadroid.com/wpm/
http://www.meadroid.com/scriptx/
MeadCo HTML printing article and samples on the MSDN:
http://msdn.microsoft.com/workshop/author/script/dhtmlprint.asp

Hello,

I have a dual interface COM component with a method that takes an
optional interface as one of its arguments, e.g. the IDL looks like

...
interface IFoo1 : IDispatch {
  HRESULT Open (
    [in] Mode Mode,
    [in, defaultvalue(NULL)] ITest* Test,
    [out, retval] IFoo2** Module );

Quote:
}

Calling this method from JScript with one argument results in a "Type
Mismatch" error.  I'm presuming that NULL gets transformed into a
variant that's not compatible with an IDispatch or IUnknown variant?
Dropping the defaultvalue modifier, and passing null as the second
argument produced the same error.  So is there any mechanism for
JScript to pass a null object pointer to a COM component, or am I
doomed to use variants explicitly here?  I'd like to avoid this if
possible as the component is also used by other languages.  I'd like to
preserve as much typing as I can at the IDL level, even if it gets
coerced to variants behind the scenes in JScript.

Thanks in advance for any help/suggestions,

Kevin Mitchell

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.



Sat, 08 Dec 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. pass a COM object reference to a WSC component

2. use of automation object methods with optional arguments

3. optional parameters in COM object methods

4. Passing arguments ByRef from VBScript to COMAdmin component

5. Need help passing arguments to a COM method...

6. passing arguments by reference in com function calls

7. Passing an Array object to a C++ COM object

8. Passing by reference to an ATL COM component

9. Passing Arrays to COM Components

10. Passing array to COM component

11. COM Object Return Multiple Arguments

12. Attach events of the external COM-object from WSC component

 

 
Powered by phpBB® Forum Software