Skip to content

Commit 675a156

Browse files
authored
Merge pull request #5572 from Rageking8/fix-syntax-error-and-update-dynamically-determining-columns-returned-to-the-consumer
Fix syntax error and update "Dynamically Determining Columns Returned to the Consumer"
2 parents ae1349f + 5fa0a6d commit 675a156

File tree

1 file changed

+44
-45
lines changed

1 file changed

+44
-45
lines changed
Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
---
2-
description: "Learn more about: Dynamically Determining Columns Returned to the Consumer"
32
title: "Dynamically Determining Columns Returned to the Consumer"
4-
ms.date: "10/26/2018"
3+
description: "Learn more about: Dynamically Determining Columns Returned to the Consumer"
4+
ms.date: 10/26/2018
55
helpviewer_keywords: ["bookmarks [C++], dynamically determining columns", "dynamically determining columns [C++]"]
6-
ms.assetid: 58522b7a-894e-4b7d-a605-f80e900a7f5f
76
---
87
# Dynamically Determining Columns Returned to the Consumer
98

10-
The PROVIDER_COLUMN_ENTRY macros normally handle the `IColumnsInfo::GetColumnsInfo` call. However, because a consumer might choose to use bookmarks, the provider must be able to change the columns returned depending on whether the consumer asks for a bookmark.
9+
The `PROVIDER_COLUMN_ENTRY` macros normally handle the `IColumnsInfo::GetColumnsInfo` call. However, because a consumer might choose to use bookmarks, the provider must be able to change the columns returned depending on whether the consumer asks for a bookmark.
1110

12-
To handle the `IColumnsInfo::GetColumnsInfo` call, delete the PROVIDER_COLUMN_MAP, which defines a function `GetColumnInfo`, from the `CCustomWindowsFile` user record in *Custom*RS.h and replace it with the definition for your own `GetColumnInfo` function:
11+
To handle the `IColumnsInfo::GetColumnsInfo` call, delete the `PROVIDER_COLUMN_MAP`, which defines a function `GetColumnInfo`, from the `CCustomWindowsFile` user record in *Custom*RS.h and replace it with the definition for your own `GetColumnInfo` function:
1312

1413
```cpp
1514
////////////////////////////////////////////////////////////////////////
@@ -23,7 +22,7 @@ public:
2322
TCHAR szText[iSize];
2423
TCHAR szCommand2[iSize];
2524
TCHAR szText2[iSize];
26-
25+
2726
static ATLCOLUMNINFO* GetColumnInfo(void* pThis, ULONG* pcCols);
2827
bool operator==(const CCustomWindowsFile& am)
2928
{
@@ -36,7 +35,7 @@ Next, implement the `GetColumnInfo` function in *Custom*RS.cpp, as shown in the
3635

3736
`GetColumnInfo` checks first to see if the OLE DB property `DBPROP_BOOKMARKS` is set. To get the property, `GetColumnInfo` uses a pointer (`pRowset`) to the rowset object. The `pThis` pointer represents the class that created the rowset, which is the class where the property map is stored. `GetColumnInfo` typecasts the `pThis` pointer to an `RCustomRowset` pointer.
3837

39-
To check for the `DBPROP_BOOKMARKS` property, `GetColumnInfo` uses the `IRowsetInfo` interface, which you can get by calling `QueryInterface` on the `pRowset` interface. As an alternative, you can use an ATL [CComQIPtr](../../atl/reference/ccomqiptr-class.md) method instead.
38+
To check for the `DBPROP_BOOKMARKS` property, `GetColumnInfo` uses the `IRowsetInfo` interface, which you can get by calling `QueryInterface` on the `pRowset` interface. As an alternative, you can use an ATL [`CComQIPtr`](../../atl/reference/ccomqiptr-class.md) method instead.
4039

4140
```cpp
4241
////////////////////////////////////////////////////////////////////
@@ -45,27 +44,27 @@ ATLCOLUMNINFO* CCustomWindowsFile::GetColumnInfo(void* pThis, ULONG* pcCols)
4544
{
4645
static ATLCOLUMNINFO _rgColumns[5];
4746
ULONG ulCols = 0;
48-
47+
4948
// Check the property flag for bookmarks; if it is set, set the zero
5049
// ordinal entry in the column map with the bookmark information.
5150
CCustomRowset* pRowset = (CCustomRowset*) pThis;
5251
CComQIPtr<IRowsetInfo, &IID_IRowsetInfo> spRowsetProps = pRowset;
53-
52+
5453
CDBPropIDSet set(DBPROPSET_ROWSET);
5554
set.AddPropertyID(DBPROP_BOOKMARKS);
5655
DBPROPSET* pPropSet = NULL;
5756
ULONG ulPropSet = 0;
5857
HRESULT hr;
59-
58+
6059
if (spRowsetProps)
6160
hr = spRowsetProps->GetProperties(1, &set, &ulPropSet, &pPropSet);
62-
61+
6362
if (pPropSet)
6463
{
6564
CComVariant var = pPropSet->rgProperties[0].vValue;
6665
CoTaskMemFree(pPropSet->rgProperties);
6766
CoTaskMemFree(pPropSet);
68-
67+
6968
if (SUCCEEDED(hr) && (var.boolVal == VARIANT_TRUE))
7069
{
7170
ADD_COLUMN_ENTRY_EX(ulCols, OLESTR("Bookmark"), 0, sizeof(DWORD),
@@ -74,58 +73,58 @@ ATLCOLUMNINFO* CCustomWindowsFile::GetColumnInfo(void* pThis, ULONG* pcCols)
7473
ulCols++;
7574
}
7675
}
77-
76+
7877
// Next, set the other columns up.
7978
ADD_COLUMN_ENTRY(ulCols, OLESTR("Command"), 1, 256, DBTYPE_STR, 0xFF, 0xFF,
8079
GUID_NULL, CCustomWindowsFile, szCommand)
8180
ulCols++;
8281
ADD_COLUMN_ENTRY(ulCols, OLESTR("Text"), 2, 256, DBTYPE_STR, 0xFF, 0xFF,
8382
GUID_NULL, CCustomWindowsFile, szText)
8483
ulCols++;
85-
84+
8685
ADD_COLUMN_ENTRY(ulCols, OLESTR("Command2"), 3, 256, DBTYPE_STR, 0xFF, 0xFF,
8786
GUID_NULL, CCustomWindowsFile, szCommand2)
8887
ulCols++;
8988
ADD_COLUMN_ENTRY(ulCols, OLESTR("Text2"), 4, 256, DBTYPE_STR, 0xFF, 0xFF,
9089
GUID_NULL, CCustomWindowsFile, szText2)
9190
ulCols++;
92-
91+
9392
if (pcCols != NULL)
9493
*pcCols = ulCols;
95-
94+
9695
return _rgColumns;
9796
}
9897
```
9998
100-
This example uses a static array to hold the column information. If the consumer doesn't want the bookmark column, one entry in the array is unused. To handle the information, you create two array macros: ADD_COLUMN_ENTRY and ADD_COLUMN_ENTRY_EX. ADD_COLUMN_ENTRY_EX takes an extra parameter, *flags*, that is needed if you designate a bookmark column.
99+
This example uses a static array to hold the column information. If the consumer doesn't want the bookmark column, one entry in the array is unused. To handle the information, you create two array macros: `ADD_COLUMN_ENTRY` and `ADD_COLUMN_ENTRY_EX`. `ADD_COLUMN_ENTRY_EX` takes an extra parameter, *`flags`*, that is needed if you designate a bookmark column.
101100
102101
```cpp
103-
////////////////////////////////////////////////////////////////////////
104-
// CustomRS.h
105-
106-
#define ADD_COLUMN_ENTRY(ulCols, name, ordinal, colSize, type, precision, scale, guid, dataClass, member) \
107-
_rgColumns[ulCols].pwszName = (LPOLESTR)name; \
108-
_rgColumns[ulCols].pTypeInfo = (ITypeInfo*)NULL; \
109-
_rgColumns[ulCols].iOrdinal = (ULONG)ordinal; \
110-
_rgColumns[ulCols].dwFlags = 0; \
111-
_rgColumns[ulCols].ulColumnSize = (ULONG)colSize; \
112-
_rgColumns[ulCols].wType = (DBTYPE)type; \
113-
_rgColumns[ulCols].bPrecision = (BYTE)precision; \
114-
_rgColumns[ulCols].bScale = (BYTE)scale; \
115-
_rgColumns[ulCols].cbOffset = offsetof(dataClass, member);
116-
117-
#define ADD_COLUMN_ENTRY_EX(ulCols, name, ordinal, colSize, type, precision, scale, guid, dataClass, member, flags) \
118-
_rgColumns[ulCols].pwszName = (LPOLESTR)name; \
119-
_rgColumns[ulCols].pTypeInfo = (ITypeInfo*)NULL; \
120-
_rgColumns[ulCols].iOrdinal = (ULONG)ordinal; \
121-
_rgColumns[ulCols].dwFlags = flags; \
122-
_rgColumns[ulCols].ulColumnSize = (ULONG)colSize; \
123-
_rgColumns[ulCols].wType = (DBTYPE)type; \
124-
_rgColumns[ulCols].bPrecision = (BYTE)precision; \
125-
_rgColumns[ulCols].bScale = (BYTE)scale; \
126-
_rgColumns[ulCols].cbOffset = offsetof(dataClass, member); \
127-
memset(&(_rgColumns[ulCols].columnid), 0, sizeof(DBID)); \
128-
_rgColumns[ulCols].columnid.uName.pwszName = (LPOLESTR)name;
102+
////////////////////////////////////////////////////////////////////////
103+
// CustomRS.h
104+
105+
#define ADD_COLUMN_ENTRY(ulCols, name, ordinal, colSize, type, precision, scale, guid, dataClass, member) \
106+
_rgColumns[ulCols].pwszName = (LPOLESTR)name; \
107+
_rgColumns[ulCols].pTypeInfo = (ITypeInfo*)NULL; \
108+
_rgColumns[ulCols].iOrdinal = (ULONG)ordinal; \
109+
_rgColumns[ulCols].dwFlags = 0; \
110+
_rgColumns[ulCols].ulColumnSize = (ULONG)colSize; \
111+
_rgColumns[ulCols].wType = (DBTYPE)type; \
112+
_rgColumns[ulCols].bPrecision = (BYTE)precision; \
113+
_rgColumns[ulCols].bScale = (BYTE)scale; \
114+
_rgColumns[ulCols].cbOffset = offsetof(dataClass, member);
115+
116+
#define ADD_COLUMN_ENTRY_EX(ulCols, name, ordinal, colSize, type, precision, scale, guid, dataClass, member, flags) \
117+
_rgColumns[ulCols].pwszName = (LPOLESTR)name; \
118+
_rgColumns[ulCols].pTypeInfo = (ITypeInfo*)NULL; \
119+
_rgColumns[ulCols].iOrdinal = (ULONG)ordinal; \
120+
_rgColumns[ulCols].dwFlags = flags; \
121+
_rgColumns[ulCols].ulColumnSize = (ULONG)colSize; \
122+
_rgColumns[ulCols].wType = (DBTYPE)type; \
123+
_rgColumns[ulCols].bPrecision = (BYTE)precision; \
124+
_rgColumns[ulCols].bScale = (BYTE)scale; \
125+
_rgColumns[ulCols].cbOffset = offsetof(dataClass, member); \
126+
memset(&(_rgColumns[ulCols].columnid), 0, sizeof(DBID)); \
127+
_rgColumns[ulCols].columnid.uName.pwszName = (LPOLESTR)name;
129128
```
130129

131130
In the `GetColumnInfo` function, the bookmark macro is used like this:
@@ -136,8 +135,8 @@ ADD_COLUMN_ENTRY_EX(ulCols, OLESTR("Bookmark"), 0, sizeof(DWORD),
136135
DBCOLUMNFLAGS_ISBOOKMARK)
137136
```
138137
139-
You can now compile and run the enhanced provider. To test the provider, modify the test consumer as described in [Implementing a Simple Consumer](../../data/oledb/implementing-a-simple-consumer.md). Run the test consumer with the provider and verify that the test consumer retrieves the proper strings from the provider.
138+
You can now compile and run the enhanced provider. To test the provider, modify the test consumer as described in [Implementing a Simple Consumer](implementing-a-simple-consumer.md). Run the test consumer with the provider and verify that the test consumer retrieves the proper strings from the provider.
140139
141140
## See also
142141
143-
[Enhancing the Simple Read-Only Provider](../../data/oledb/enhancing-the-simple-read-only-provider.md)<br/>
142+
[Enhancing the Simple Read-Only Provider](enhancing-the-simple-read-only-provider.md)

0 commit comments

Comments
 (0)