Microsoft KB Archive/198017

= BUG: You receive an "Unable to create the function" error message when you try to add a method as the variable type in the ATL Interface Wizard with Visual C++ =

Article ID: 198017

Article Last Modified on 6/1/2005

-

APPLIES TO

 Microsoft ActiveX Template Library 3.0, when used with:  Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Professional Edition

 Microsoft Visual C++ 6.0 Standard Edition 

-

<div class="notice_section">

This article was previously published under Q198017

<div class="symptoms_section">

SYMPTOMS
In the ATL Interface Wizard with Visual C++ 6.0, you receive the following error message:

"Unable to create the function because the header or the

implementation file could not be found."

This problem occurs when you add a method that has either SAFEARRAY(oleautomationtype)" or "SAFEARRAY(oleautomationtype)*" as the variable type. oleautomationtype is an OLE automation-compatible data type.

<div class="cause_section">

CAUSE
This is due to a bug in the ATL Interface Wizard.

<div class="workaround_section">

WORKAROUND
Add these methods by manually editing the .idl, .h, and .cpp files.

The following shows the changes when adding two methods (called Test and Test2 that have SAFEARRAY(BSTR)* and SAFEARRAY(BSTR), respectively) to an interface called IATLObj. IATLObj is implemented by an ATL class called CATLObj.

<ol>  Add this code for the new methods in the .IDL file: interface IATLObj : IDispatch {        [id(1)] HRESULT Test([out] SAFEARRAY(BSTR) *ppArrayBstr); [id(2)] HRESULT Test2([in] SAFEARRAY(BSTR) pArrayBstr); };                       </li>  Add this code to the .H file for the ATL COM object: STDMETHOD(Test)(SAFEARRAY **ppArrayBstr); STDMETHOD(Test2)(SAFEARRAY *pArrayBstr); </li>  And add this code to the .CPP file for the ATL COM object: STDMETHODIMP CATLObj::Test(SAFEARRAY **ppArrayBstr) {        return S_OK; }

STDMETHODIMP CATLObj::Test2(SAFEARRAY *pArrayBstr) {        return S_OK; } </li></ol>

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

<div class="moreinformation_section">

Steps to reproduce the behavior

 * 1) Create a new ATL/COM Application Wizard Project.
 * 2) Insert a new ATL COM Object with the default settings.
 * 3) Add a new method with the ATL COM Object Wizard by right-clicking the interface to add the method and by selecting "Add Method."
 * 4) Give the method a name.
 * 5) Add one parameter with SAFEARRAY(BSTR)* as the type For example: [out] SAFEARRAY(BSTR) *pArrayBSTR. Note that when you click OK on the "Add Method to Interface" dialog box, a message box appears with the error mentioned above.

<div class="references_section">