Microsoft KB Archive/315485

= BUG: You may receive unexpected results when you use ATL automation components in a scripting client =

Article ID: 315485

Article Last Modified on 1/6/2006

-

APPLIES TO


 * Microsoft Visual C++ 2005 Express Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition

-



This article was previously published under Q315485



SYMPTOMS
When you use attributed Active Template Library (ATL) automation components in a scripting client, you may receive unexpected results on a computer that is running Microsoft Windows 95, Microsoft Windows 98, or Microsoft Windows Millennium Edition (Windows Me).



CAUSE
Scripting engines resolve the function calls by internally calling the IDispatch::GetIDsOfNames implementation of the component. The ATL attribute provider generates the code for GetIDsOfNames for the component. This implementation calls the lstrcmpiW function to do the case insensitive string comparison. This function is not supported on computers running Windows 95, Windows 98, and Windows Me because of UNICODE dependency.



RESOLUTION
To resolve the problem, do one of the following:   Do not permit the ATL attribute provider to generate the IDispatch implementation for your component. Instead, derive your class from IDispatchImpl, as in the following sample code: class ATL_NO_VTABLE CMyComObject : //public IMyComObject ,/*This is put by the wizard.*/ public IDispatchImpl,/*Use this, instead.*/ public IObjectSafetyImpl -or-

 Do not use attributed code.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 Create a new ATL DLL attributed project named Project1. Accept the defaults.</li> Do one of the following:   On the Project menu, click Add Class, and then add the following sample code under the module declaration in Project1.cpp: [dispinterface, helpstring(&quot;My Bear Interface&quot;)] __interface IDisp : IDispatch{ [id(0)] HRESULT Method1([in]int i); [id(1)] HRESULT Method2([out] int* pi); };

[ coclass,progid=&quot;Bear.Bell.1&quot;, default(IDisp)] struct CBear : IDisp{

int _mi; HRESULT Method1(int i) { _mi = i;   printf(&quot;In Method1\n&quot;); return S_OK; } HRESULT Method2(int* pi) {      *pi = _mi; printf(&quot;In Method2\n&quot;); return S_OK; }

}; -or-

</li> On the Project menu, click Add Class. In the Add Class dialog box, click ATL Simple Object, and then click Open. Type the name of the object; accept the defaults. Add the methods similar to those shown earlier.</li></ul> </li> Build the project.</li>  Create a client script named Client.vbs that contains the following code: set obj = CreateObject(&quot;Bear.Bell.1&quot;) v=10 obj.Method1 v obj.Method2 v2 wscript.echo &quot;v2 = &quot; &v2 </li> Copy Project1.dll to a client computer running Windows 95, Windows 98, or Windows Me, and then register the project.</li> Copy Client.vbs to the client computer, and then run the following command at a command prompt:

cscript.exe Client.vbs </li></ol>

<div class="references_section">