I had the following code:
wchar_t recordsText[64] = L"Records: ";
std::wstringstream ss2;
ss2 << c;
wcsncat_s(recordsText, ss2.str().c_str(), sizeof(ss2.str().c_str()));
((CButton*)GetDlgItem(IDC_RECORDS))->SetWindowTextW(recordsText);
It worked pretty well, but i want to put it into a function... nothing easier i thought. but i get an stupid error.
my function was this one:
BOOL refreshTextField(CButton* item, wchar_t* label, long long* number){
std::wstringstream ss;
ss << number;
wcsncat_s(label, ss.str().c_str(), sizeof(ss.str().c_str()));
item->SetWindowTextW(label);
return true;
}
but the wcsncat_s doesnt like my "label" because its an array and the function is called like this:
refreshTextField(((CButton*)GetDlgItem(IDC_SENT_PACKAGES)), L"Packages send: ", &sentPackages);
(btw: i know it shouldn't be casted to a CButton because it's an edit-field :-D , but that doesnt matter at the moment.)
the problem is the wchar_t array, i dont know how to get it into my function correctly. hope you can give me a quit answer.
i already tried this:
BOOL refreshTextField(CButton* item, wchar_t** label, long long* number){
//...
wcsncat_s(*label, sizeof(*label), ss.str().c_str(), sizeof(ss.str().c_str()));
//....
}
and this:
BOOL refreshTextField(CButton* item, wchar_t* label, long long* number){
//...
wcsncat_s(label, sizeof(*label), ss.str().c_str(), sizeof(ss.str().c_str()));
//....
}
EDIT:
So the solution was this:
call:
refreshTextField(mySelectedUIItem, L"testlabel", sizeof(L"testlabel"), 4);
function:
BOOL refreshTextField(CButton* item, wchar_t* label, size_t lableSize, long long* number)
{
std::wstringstream ss;
ss << number;
wcsncat_s(label, labelSize, ss.str().c_str(), ss.str().length());
//...
}