Microsoft KB Archive/828558

= BUG: ATL consumer templates do not compile when you use the CArrayRowset class in Visual C++ .NET or in Visual C++ 2005 =

Article ID: 828558

Article Last Modified on 4/19/2007

-

APPLIES TO


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

-





SYMPTOMS
The CCommand class of Microsoft ATL (Active Template Library) provides methods to set a command and to execute a command. However, in the CCommand ATL consumer template, when you define the TRowset parameter as CArrayRowset, and you use Microsoft Visual C++ .NET or Microsoft Visual C++ 2005 to compile your code, you may receive following compiler error message:

error C3200: 'ATL::CArrayRowset' : invalid template argument for template parameter 'TRowset', expected a class template

with

[

TAccessor=CUserDataAccessor

]

see reference to class template instantiation 'ATL::CCommand' being compiled

with

[

TAccessor=ATL::CAccessor,

TRowset=ATL::CArrayRowset

]

Note In Microsoft Visual C++ 6.0, you do not receive this compiler error.



WORKAROUND
To work around this problem, change the definition of the CCommand ATL consumer template from the following CCommand< CAccessor, CArrayRowset > cmd; to the following: CCommand< CAccessor, CArrayRowset > cmd; To do this, follow these steps:  In Solution Explorer, double-click ATLCommand.cpp under the Source Files folder.  Locate the following code in the main function: CCommand< CAccessor, CArrayRowset > cmd; </li>  Replace the code that you located in step 2 with the following code: // This definition is broken in Visual Studio .NET 2002 and in Visual Studio .NET 2003. // CCommand< CAccessor<CUserDataAccessor>, CArrayRowset<CUserDataAccessor> > cmd; // The following statement represents the workaround: CCommand< CAccessor<CUserDataAccessor>, CArrayRowset > cmd; </li> Press the CTRL+SHIFT+B key combination to build the code.

Notice that the code compiles without any errors.</li></ol>

<div class="status_section">

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

<div class="moreinformation_section">

Steps to Reproduce the Behavior
<ol> Start Microsoft Visual C++ 6.0.</li> On the File menu, click New, and then click Win32 Console Application on the Projects tab of the New dialog box.</li> In the Project name text box, type ATLCommand, and then click OK.</li> In the Win32 Console Application - Step 1 of 1 dialog box, click to select A &quot;Hello, World&quot; Application., and then click Finish.</li> Click OK in the New Project Information dialog box.</li> Verify that the Workspace window is visible. If this window is not visible, press ALT+0.</li> In the Workspace window, double-click ATLCommand.cpp under Source Files.</li>  Replace all the code in the ATLCommand.cpp file with the following code:
 * 1) include &quot;stdafx.h&quot;


 * 1) define UNICODE
 * 2) define _UNICODE


 * 1) pragma pack(push, 1)
 * 2) include <atldbcli.h>
 * 3) pragma pack(pop)


 * 1) include <oledberr.h>
 * 2) include <atlbase.h>
 * 3) include


 * 1) define DBINITCONSTANTS

using namespace std;

class CUserData { public: TCHAR m_UserName[64]; double m_CardNo; LONG m_PinNo; BYTE m_UserEnabled; BYTE m_UserGroup; LONG m_UserNum; LONG m_UserOptions; };

class CUserDataAccessor : public CUserData {   public:

BEGIN_COLUMN_MAP(CUserDataAccessor) COLUMN_ENTRY(1, m_UserName) COLUMN_ENTRY(2, m_CardNo) COLUMN_ENTRY(3, m_PinNo) COLUMN_ENTRY(4, m_UserEnabled) COLUMN_ENTRY(5, m_UserGroup) COLUMN_ENTRY(6, m_UserNum) COLUMN_ENTRY(7, m_UserOptions) END_COLUMN_MAP };

int main(int argc, char* argv[]) {   USES_CONVERSION; CoInitialize(NULL);

//HRESULT hr; CDataSource ds; CSession session; CCommand< CAccessor<CUserDataAccessor>, CArrayRowset<CUserDataAccessor> > cmd; CoUninitialize; return 0; } </li> Press F7 to build the application.

The code compiles without any errors, and the ATLCommand.exe file is built.</li> Quit Visual C++ 6.0.</li> Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.</li> On the File menu, point to Open, and then click Project.</li> In the Open Project dialog box, locate the folder that contains the files of the application that you created in step 5.</li> In the Files of type list, click Compatible Workspace Files.</li> <li>In the Open Project dialog box, click ATLCommand, and then click Open.</li> <li>In the Visual C++ Project dialog box, click Yes to convert and to open this project.</li> <li>Press the CTRL+SHIFT+B key combination to build the solution.

You receive the compilation error that is mentioned in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">