Re: CString Array to LPCTSTR *
- From: David Wilkinson <no-reply@xxxxxxxxxxxx>
- Date: Tue, 19 Sep 2006 16:21:51 -0400
Vipin wrote:
c_str() returns a pointer to the internal string, but I don't have a mechanism to resize the string to certain number of characters unless I assign a dummy string that wide. CString is pretty useful in the case I mentioned, I call RegQueryValue(...) with NULL and then I get the required size of memory, I use GetBuffer(...) and then pass in the pointer returned by it to RegQueryValue(...) again. Also c_str() returns a const char *, GetBuffer(...) gets me LPTSTR which is not constant. ofcourse I can cast the const char * to char* to make it work
CString is well suited for windows programming when I can use with win32 apis, but std::string falls short.
Vipin:
Personally I do not like GetBuffer/ReleaseBuffer. And it's no easier than using the standard library in your case.
long nData;
RegQueryValue(..., NULL, &nData);
Now there is no convenience difference between
std::vector<TCHAR> data(nData+1);
RegQueryValue(..., &data[0], nData);
CString str(&data[0]);
and
CString str;
RegQueryValue(..., str.GetBuffer(nData+1), nData);
str.ReleaseBuffer();
If you do not actually need the CString, then the standard library method is a shorter way to get a LPTSTR.
David Wilkinson
.
- Follow-Ups:
- Re: CString Array to LPCTSTR *
- From: Vipin
- Re: CString Array to LPCTSTR *
- From: Ajay Kalra
- Re: CString Array to LPCTSTR *
- From: Tom Serface
- Re: CString Array to LPCTSTR *
- References:
- Re: CString Array to LPCTSTR *
- From: Ajay Kalra
- Re: CString Array to LPCTSTR *
- From: Vipin
- Re: CString Array to LPCTSTR *
- From: Ajay Kalra
- Re: CString Array to LPCTSTR *
- From: Vipin
- Re: CString Array to LPCTSTR *
- Prev by Date: Messages in MFC
- Next by Date: Re: templates please help
- Previous by thread: Re: CString Array to LPCTSTR *
- Next by thread: Re: CString Array to LPCTSTR *
- Index(es):
Relevant Pages
|