PRB: OLE DB Consumer Template Wizard Requires ATL Project
ID: Q190959
|
The information in this article applies to:
-
Microsoft Visual C++, 32-bit Editions, version 6.0
SYMPTOMS
If you attempt to add an ATL OLE DB Consumer class (with the ATL Object
Wizard) to a non-ATL Visual C++ MFC project, you are prompted to add ATL
support to the project. If you choose No, the Wizard will not continue.
CAUSE
The ATL OLE DB Consumer classes do not require ATL support; however, the
ATL Object Wizard requires an ATL project.
RESOLUTION
The ATL OLE DB Consumer classes do not require full ATL support. For
example, you can use an ATL OLE DB Consumer class in a console project that
does not have a global CComModule object and is not set up to be an ATL COM
.exe or .dll file.
If you want to add one or more OLE DB Consumer Template classes to a non-
ATL project, create a temporary ATL project to create the classes and then
manually transfer the class files to your non-ATL project. The ATL OLE DB
Consumer Template wizard creates a single .h file each time you run it.
Transfer the wizard-generated .h files to your actual project and then add
the following code to the main header in your project:
#include <atldbcli.h>
// You must call CoInitialize before the first call to an ATL
// OLE DB Consumer class or you will get an hresult of
// 0x0040cba8, which is "CoInitialize has not been called."
// Because this structure has global scope, it is constructed first
// and destroyed last and thus automatically handles the necessary
// COM initialization and termination calls.
struct HandleCOM
{
HandleCOM() { ::CoInitialize(NULL); }
~HandleCOM() { ::CoUninitialize(); }
} _HandleCOM_;
The wizard-generated ATL OLE DB Consumer Templates require only the
Atldbcli.h ATL header file in order to compile properly.
STATUS
This behavior is by design.
MORE INFORMATION
Follow these steps to create a temporary ATL project:
- Open Visual Studio. On the File menu, click New.
- Click the Project tab and select ATL COM AppWizard.
- Type a name in the project box for your temporary project, and click OK.
- Click Finish and then click OK.
You now have a temporary ATL project. Follow these steps to create an ATL
OLE DB Consumer Template class:
- On the Insert menu, click New ATL Object.
- Select Category of Data Access, select the Consumer object, and click
Next.
- Click Select DataSource to set up your data source and select the
desired table.
- Make a note of the name in the .H box and click OK.
The wizard creates a single .h file with all of the code necessary to
create an OLE DB Consumer Template class. To use the class, just copy the
wizard-generated .h file to your actual project and include Atldbcli.h in
your project. You can use the temporary ATL project to generate as many
classes as you need.
NOTE: You need to call CoInitialize in your application prior to opening
any OLE DB Consumer Template class because these classes use COM. The
HandleCOM structure in the RESOLUTION section above can be used to
automatically make the appropriate COM calls.
Additional query words:
kbTemplate kbATL kbDatabase kbOLEDB kbvc600
Keywords : kbtemplate kbwizard kbDatabase kbVC600 kbATL300 kbGrpOLEDB
Version : winnt:6.0
Platform : winnt
Issue type : kbprb