PRB: Passing Parameters By Reference to a VC COM Object
ID: Q197957
|
The information in this article applies to:
-
Active Server Pages
-
Microsoft Visual C++, 32-bit Editions, versions 5.0, 6.0
-
Microsoft Internet Information Server versions 4.0, 5.0
SYMPTOMS
When passing a parameter to a COM Component's method in Active Server Pages
(ASP) using VBScript, either the following error occurs:
Microsoft VBScript runtime error '800a000d' Type mismatch
Or the value stored in the variable passed to the method is not changed.
CAUSE
VBScript will pass parameters to a method by value if the argument's data
type is NOT declared as a variant and the parameter is passed by reference
if the argument's data type is declared as variant by the method.
RESOLUTION
Parameters to be passed as [out] parameters (that is, by reference) to a
method should always be declared as a pointer to a variant data type by the
method, while [in] parameters (that is, passed by value) can be declared as
any type.
STATUS
This behavior is by design.
MORE INFORMATION
Steps to Reproduce Behavior
- Create an ATL DLL Project called "ByRefProj."
- Insert an ATL Object named "ByRefObj."
- Add a method with the following information:
Method Name: ByRefMethod
Parameters : [out]BSTR* bstrVal
- Implement the method as follows:
STDMETHODIMP CByRefObj::ByRefMethod( BSTR* bstrVal )
{
CComBSTR bstrRtnVal = L"This variable is passed by Reference";
*bstrVal = bstrRtnVal.Detach();
return S_OK;
}
- Create an ASP page that calls this method:
<%
Dim objTest, strByRefVal
Set objTest = Server.CreateObject("ByRefProj.ByRefObj")
objTest.ByRefMethod strByRefVal
%>
- Run ASP and the following error occurs:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'ByRefMethod'
To fix this behavior without passing in a reference variable:
- Change the IDL declaration in the ByRefProj.idl file, to add 'retval':
[id(1), helpstring("method ByRefMethod")] HRESULT ByRefMethod([out, retval] BSTR* bstrVal);
- Change the ASP page as follows:
%
Dim objTest
Set objTest = Server.CreateObject("ByRefProj.ByRefObj")
Response.Write objTest.ByRefMethod()
>
Additional query words:
Keywords : kberrmsg kbASP kbCOMt kbVBScript kbGrpASP kbCodeSnippet kbiis400 kbiis500
Version : winnt:5.0,6.0
Platform : winnt
Issue type : kbprb