StringCbPrintf - multiple params

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to concat multiple params. My code only grabs the first param.

/*******/

// Param1: OLE2T(menuItemsData[idCmd])
// Param2: pStrClipboardText


int const arraysize = 30;
TCHAR pszDest[arraysize];
size_t cbDest = arraysize * sizeof(TCHAR);
LPCTSTR pszFormat = TEXT("%s");

HRESULT hr = StringCbPrintf(pszDest, cbDest,
pszFormat,OLE2T(menuItemsData[idCmd]),_T(pStrClipboardText));

what am i doing wrong??

Thanks
 
mgonzales3 said:
I'm trying to concat multiple params. My code only grabs the first param.

/*******/

// Param1: OLE2T(menuItemsData[idCmd])
// Param2: pStrClipboardText


int const arraysize = 30;
TCHAR pszDest[arraysize];
size_t cbDest = arraysize * sizeof(TCHAR);
LPCTSTR pszFormat = TEXT("%s");

HRESULT hr = StringCbPrintf(pszDest, cbDest,
pszFormat,OLE2T(menuItemsData[idCmd]),_T(pStrClipboardText));

what am i doing wrong??

Thanks

Format is TEXT("%s"), then it will only process first parameter. Try
_T("%s, %s")

For
string concatenation, std::basic_stringstream<TCHAR> is recommended.

#include <sstream>

std::basic_stringstream<TCHAR> ss;
ss<< OLE2T(menuItemsData[idCmd]) << _T(pStrClipboardText);
 
Back
Top