Help and Support
 

powered byLive Search

PRB: Passing Parameters By Reference to a VC COM Object

Article ID:197957
Last Review:March 21, 2005
Revision:4.1
This article was previously published under Q197957
On This Page

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.

Back to the top

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.

Back to the top

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.

Back to the top

STATUS

This behavior is by design.

Back to the top

MORE INFORMATION

Steps to Reproduce Behavior

1.Create an ATL DLL Project called "ByRefProj."
2.Insert an ATL Object named "ByRefObj."
3.Add and implement the method.
a. Add a method with the following information:
      Method Name: ByRefMethod
      Parameters : [out]BSTR* bstrVal
  
						
b. 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;
}
						
4.Create an Active Server Pages (ASP) page that calls this method:
<%
  Dim objTest, strByRefVal
  Set objTest = Server.CreateObject("ByRefProj.ByRefObj")
  objTest.ByRefMethod strByRefVal
%>
5.Run ASP, and the following error occurs:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'ByRefMethod'
To fix this problem, change the type to VARIANT:
1.Change the IDL declaration in the ByRefProj.idl file to:
[id(1), helpstring("method ByRefMethod")] HRESULT ByRefMethod([out] VARIANT* vVal); 
						
2.Change the method in the .h and .cpp file. Change the method as follows:
// Where m_bstr is a BSTR member of SomeComObject.
vVal->vt = VT_BSTR;
vVal->bstrVal = m_bstr.Copy();
						
3.Recompile.

Back to the top

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
244012 (http://support.microsoft.com/kb/244012/EN-US/) INFO: Type Mismatch Errors When You Pass Parameters from ASP to a Visual Basic Component

Back to the top


APPLIES TO
Microsoft Active Server Pages 4.0
Microsoft Visual C++ 5.0 Enterprise Edition
Microsoft Visual C++ 6.0 Enterprise Edition
Microsoft Visual C++ 5.0 Professional Edition
Microsoft Visual C++ 6.0 Professional Edition
Microsoft Visual C++, 32-bit Learning Edition 6.0
Microsoft Internet Information Server 4.0
Microsoft Internet Information Services 5.0

Back to the top

Keywords: 
kberrmsg kbcodesnippet kbprb KB197957

Back to the top

Article Translations

 

Related Support Centers

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.