Design question (working with ATL OLE DB classes)....
-
So I have a lot of different C++ objects with members. Strings, ints etc. Objects get populated from database. Used to do it using MFC ODBC classes. Then I decided to go OLE DB. Wow! So. Now instead of
CRecordset
we useCAccessor<>
, right? To map members to fields now I have to useTCHAR
orCComBSTR
for strings, right? But I'd like to keep my objects asCString
orstd::string
. I don't want to change all my code to operate withCComBSTR
and I don't want make parallel just members to transfer data from database to my members. What do I do then? Is there a way to makeCOLUMN_ENTRY
to acceptCString
orstd::string
? Or somehow make an automatic transfer from one globalCComBSTR
(that would be used to retrieve the data) to those members? Confusing? :) -
So I have a lot of different C++ objects with members. Strings, ints etc. Objects get populated from database. Used to do it using MFC ODBC classes. Then I decided to go OLE DB. Wow! So. Now instead of
CRecordset
we useCAccessor<>
, right? To map members to fields now I have to useTCHAR
orCComBSTR
for strings, right? But I'd like to keep my objects asCString
orstd::string
. I don't want to change all my code to operate withCComBSTR
and I don't want make parallel just members to transfer data from database to my members. What do I do then? Is there a way to makeCOLUMN_ENTRY
to acceptCString
orstd::string
? Or somehow make an automatic transfer from one globalCComBSTR
(that would be used to retrieve the data) to those members? Confusing? :)ATL has a version of CString in atlstr.h. You should be able to use this.
-
ATL has a version of CString in atlstr.h. You should be able to use this.
No,no,no. I need in VC 6.
-
No,no,no. I need in VC 6.
VC6 comes with ATL...
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
So I have a lot of different C++ objects with members. Strings, ints etc. Objects get populated from database. Used to do it using MFC ODBC classes. Then I decided to go OLE DB. Wow! So. Now instead of
CRecordset
we useCAccessor<>
, right? To map members to fields now I have to useTCHAR
orCComBSTR
for strings, right? But I'd like to keep my objects asCString
orstd::string
. I don't want to change all my code to operate withCComBSTR
and I don't want make parallel just members to transfer data from database to my members. What do I do then? Is there a way to makeCOLUMN_ENTRY
to acceptCString
orstd::string
? Or somehow make an automatic transfer from one globalCComBSTR
(that would be used to retrieve the data) to those members? Confusing? :) -
VC6 comes with ATL...
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
But ATL in VC6 doesn't come with atlstr.h. It's in VC7. :((
-
Take a look at _bstr_t and _variant_t http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_pluslang__bstr_t.asp[^]
-- signature under construction --
-pete
Yeah. But how does it help? I can get data using
CComBSTR
just as well. But these macros:BEGIN_COLUMN_MAP(CUserRowset) COLUMN_ENTRY(1, m_bstrID) COLUMN_ENTRY(2, m_bstrDescription) .... END_COLUMN_MAP()
for linking fields to members require members to beCComBSTR
(or_bstr_t
you are talking about). But my members areCString
and/orstd:string
and I don't want to convert the rest of my code to use BSTRs. -
Yeah. But how does it help? I can get data using
CComBSTR
just as well. But these macros:BEGIN_COLUMN_MAP(CUserRowset) COLUMN_ENTRY(1, m_bstrID) COLUMN_ENTRY(2, m_bstrDescription) .... END_COLUMN_MAP()
for linking fields to members require members to beCComBSTR
(or_bstr_t
you are talking about). But my members areCString
and/orstd:string
and I don't want to convert the rest of my code to use BSTRs.inner wrote: I don't want to convert the rest of my code to use BSTRs. You must whenever using COM interfaces. It is the COM form of string. Unless you want to use byte arrays which are not easier. At least _bstr_t has simple conversion interface to char and wchar making life easy to use CString and std::string/wstring :cool:
-- signature under construction --
-pete