Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9161879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:04:37+00:00 2026-06-17T14:04:37+00:00

I had the following code: wchar_t recordsText[64] = LRecords: ; std::wstringstream ss2; ss2 <<

  • 0

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 😀 , 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());
    //...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:04:38+00:00Added an answer on June 17, 2026 at 2:04 pm

    {Edit}

    When you want to use the function template, you must match all parameter types. So you must pass the length of the string instead of a second copy of the c_str() result to the wcsncat_s template:

    wcsncat_s(recordsText, ss2.str().c_str(), ss2.str().length());
    

    This will resolve to the prototype

    template <size_t size>
    errno_t _mbsncat_s(
       unsigned char (&strDest)[size],
       const unsigned char *strSource,
       size_t count
    ); // C++ only
    

    {/Edit}

    Without the template the following applies:

    You can’t pass an array to a function. The function will only accept the pointer. The array can be well accessed with the pointer inside the function. But you lose the information about the array size.

    Since the pointer only points to the first element of the array you can’t use

    sizeof(*somePointer);
    

    because this gives you the size of the first array element.

    You need to change the parameter list of refreshTextField. Since the label argument points to an output variable you need the size of the variable as an additional parameter. e.g.:

    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());
        //...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I initially had the following code: Boolean successCheckPoint = false; Boolean failureCheckPoint = false;
Recently I attended a lecture concerning some design patterns: The following code had been
Somewhere here on Stack Overflow, I had found the following code some day which
I had no problem at all running the following code on a local server,
I have the following code setup: http://jsfiddle.net/bABHU/2/ Had to change it a little bit
I've been using the following code to move views around, and never had a
If I had to following file on my development branch: # file.rb class Code
I had the following code: NSData * JSONData = [MyJSON dataWithJSONObject:highlightItemsArray]; if ([JSONData isNotNull]){
I had the following code query = query.Where(device => GetDeviceDistanceFromGeocode(geocode, device) <= distanceMetres); private
If I had the following code below, how would I display the usernames under

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.