Storing Strings in the OLE DB Provider

In MyProviderRS.h, the ATL Object Wizard creates a default User Record called CWindowsFile. To handle the two strings, either edit CWindowsFile or add your own User Record, as shown here:

////////////////////////////////////////////////////////////////////////
class CAgentMan: 
   public WIN32_FIND_DATA
   DWORD dwBookmark;              // Add this
   TCHAR szCommand[256];          // Add this
   TCHAR szText[256];             // Add this
   TCHAR szCommand2[256];         // Add this
   TCHAR szText2[256];            // Add this
{
public:
BEGIN_PROVIDER_COLUMN_MAP(CAgentMan)
   PROVIDER_COLUMN_ENTRY("FileAttributes", 1, dwFileAttributes)
   PROVIDER_COLUMN_ENTRY("FileSizeHigh", 2, nFileSizeHigh)
   PROVIDER_COLUMN_ENTRY("FileSizeLow", 3, nFileSizeLow)
   PROVIDER_COLUMN_ENTRY("FileName", 4, cFileName)
   PROVIDER_COLUMN_ENTRY("AltFileName", 5, cAlternateFileName)
END_PROVIDER_COLUMN_MAP()
   bool operator==(const CAgentMan& am) // This is optional 
   {
      return (lstrcmpi(cFileName, wf.cFileName) == 0);
   }
};

The data members szCommand and szText represent the two strings, with szCommand2 and szText2 providing additional columns if needed. The data member dwBookmark is not needed for this simply read-only provider, but will be used later to add an IRowsetLocate interface. The == operator compares instances. (Implementing this operator is optional.)

To support the two strings, the PROVIDER_COLUMN_MAP needs modification as well. Replace the PROVIDER_COLUMN_MAP shown above with the one shown here:

BEGIN_PROVIDER_COLUMN_MAP()
    PROVIDER_COLUMN_ENTRY_STR(OLESTR("Command"), 1, 256, GUID_NULL, CAgentMan, szCommand)
    PROVIDER_COLUMN_ENTRY_STR(OLESTR("Text"),2, 256, GUID_NULL, CAgentMan, szText) 
    PROVIDER_COLUMN_ENTRY_STR(OLESTR("Command2"), 3, 256, GUID_NULL, CAgentMan, szCommand2)
    PROVIDER_COLUMN_ENTRY_STR(OLESTR("Text2"),4, 256, GUID_NULL, CAgentMan, szText2)
END_PROVIDER_COLUMN_MAP()

When this is done, your provider should be ready to compile and run. To test the provider, you need a consumer with matching functionality. Implementing a Simple Consumer shows how to create such a test consumer. Run the test consumer with the provider. Verify that the test consumer retrieves the proper strings from the provider when you click the Run button on the test consumer dialog box.

Once you have successfully tested your provider, you may want to enhance its functionality by implementing additional interfaces. An example is shown in the next section, Enhancing the Simple Read-Only Provider.