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



The information in this article applies to:

  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET (2002)

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<IMyComObject>,/*Use this, instead.*/ 
    	public IObjectSafetyImpl<CMyComObject ,
    INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA>
    					
    -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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a new ATL DLL attributed project named Project1. Accept the defaults.
  2. 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("My Bear Interface")]
      __interface IDisp : IDispatch{
             [id(0)] HRESULT Method1([in]int i);
             [id(1)] HRESULT Method2([out] int* pi);
      };
      
      [ coclass,progid="Bear.Bell.1", default(IDisp)]
      struct CBear : IDisp{
      
      int _mi;
      HRESULT Method1(int i)
      {	
      	_mi = i;
      	printf("In Method1\n");
      	return S_OK;
      }
      HRESULT Method2(int* pi)
      {	
      	*pi = _mi;
      	printf("In Method2\n");
      	return S_OK;
      }
      
      };
      						
      -or-

    • 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.
  3. Build the project.
  4. Create a client script named Client.vbs that contains the following code:
    set obj = CreateObject("Bear.Bell.1")
    v=10
    obj.Method1 v
    obj.Method2 v2
    wscript.echo "v2 = " &v2
    					
  5. Copy Project1.dll to a client computer running Windows 95, Windows 98, or Windows Me, and then register the project.
  6. Copy Client.vbs to the client computer, and then run the following command at a command prompt:

    cscript.exe Client.vbs

REFERENCES

For more information, see the following articles in the Microsoft Developer Network (MSDN) Library:

Modification Type:MajorLast Reviewed:1/6/2006
Keywords:kbbug kbpending KB315485 kbAudDeveloper