Hi,

I need to call a function, like dummy_fun( LPCTSTR * ppStr ), the ppStr
parameter's data is stored in a database, so this parameter cannot be
initialized using syntax like LPCTSTR ppStr[] = {_T("AAA"), ..., NULL }.

Following code is used to retrieve data from database and stored them to a
vector and construct the ppStr parameter.

//...
std::vector<CString> vs;
while ( SUCCEEDED(hr) && hr != DB_S_ENDOFROWSET) {
DBSTATUS dt;
rs.GetStatus(_T("ItemText"), &dt);
if (dt == DBSTATUS_S_OK) {
CString str((LPCTSTR)rs.GetValue(_T("ItemText")));
if (!str.IsEmpty()) {
vs.push_back(str);
}
}
hr = rs.MoveNext();
}

LPCTSTR *ppStr = new LPCTSTR[vs.size() + 1];

size_t i = 0, vsMax = vs.size();
while ( i < vsMax) { ppStr[i] = vs[i]; ++i;}
ppStr[vsMax] = NULL; // terminating NULL
dummy_function( ppStr ); // This function has a LPCTSTR * parameter
delete[] ppStr;

//...

Is it the way to do it ?


By the way, it is not a MFC project. I tried to use (LPCTSTR*)&vs[0] also,
but don't know how to put a NULL at the end.

--
peter lin