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 3615702
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:24:23+00:00 2026-05-18T22:24:23+00:00

As a follow-up of this question (Message compiler replacement in Linux gcc), I have

  • 0

As a follow-up of this question (Message compiler replacement in Linux gcc), I have the following problem:

When using MC.exe on Windows for compiling and generating messages, within the C++ code I call FormatMessage, which retrieves the message and uses the va_list *Arguments parameter to send the varied message arguments.
For example:
messages.mc file:

MessageId=1
Severity=Error
SymbolicName=MULTIPLE_MESSAGE_OCCURED
Language=English
message %1 occured %2 times.
.

C++ code:

void GetMsg(unsigned int errCode, wstring& message,unsigned int paramNumber, ...)
{   
    HLOCAL msg;
    DWORD ret;
    LANGID lang = GetUserDefaultLangID();
    try
    {
        va_list argList;
        va_start( argList, paramNumber );
        const TCHAR* dll = L"MyDll.dll";
        _hModule = GetModuleHandle(dll);
        ret =::FormatMessage(
            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_IGNORE_INSERTS,
            _hModule,
            errCode,
            lang,
            (LPTSTR) &msg,
            0,
            &argList );
        if ( 0 != ret )
        {
            unsigned int count = 0 ;
            message = msg;
            if (paramNumber>0)
            {
                wstring::const_iterator iter;
                for (iter = message.begin();iter!=message.end();iter++)
                {
                    wchar_t xx = *iter;
                    if (xx ==L'%')
                        count++;
                }
            }
            if ((count == paramNumber) && (count >0))
            {

                ::LocalFree( msg );
                ret =::FormatMessage(
                    FORMAT_MESSAGE_ALLOCATE_BUFFER |
                    FORMAT_MESSAGE_FROM_HMODULE,
                    _hModule,
                    errCode,
                    GetUserDefaultLangID(),
                    (LPTSTR) &msg,
                    0,
                    &argList );
            }
            else if (count != paramNumber)
            {
                wstringstream tmp;
                wstring messNumber;
                tmp << (errCode & 0xFFFF);
                tmp >> messNumber;
                message = message +L"("+ messNumber + L"). Bad Format String. ";
            }
        }
        ::LocalFree( msg );
    }
    catch (...)
    {
        message << L"last error: " << GetLastError();
    }
    va_end( argList );
}

Caller code:

wstring message;
GetMsg(MULTIPLE_MESSAGE_OCCURED, message,2, "Error message", 5);

Now, I wrote a simple script to generate a .msg file from the .mc file, and then I use gencat to generate a catalog from it.

But is there a way to use the formatted strings as they contain %1, %2, etc. and NOT the general (%d, %s…) format?

Please note, that the solution has to be generic enough for each possible message with each posible types\ arguments order…

Is it possible at all?

Thank you.

  • 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-05-18T22:24:24+00:00Added an answer on May 18, 2026 at 10:24 pm

    First of all functions like printf support positioned format:

    printf("%2$s, %1$d", salary, name);
    

    For C++, beside the C solution there is a boost::format library:

    std::cout << boost::format("%2%, %1%") % salary % name;
    

    Also if you are moving software to Linux I would suggest use “different” approach for localization: use either gettext or boost.locale library.

    And instead of this:

    wstring message;
    GetMsg(MULTIPLE_MESSAGE_OCCURED, message,2, "Error message", 5);
    

    Use :

    C/gettext:

    snprintf(msg,sizeof(msg),gettext("This is the message to %1$s about %2$s"),who,what);
    

    C++/gettext:

    using boost::format;
    std::ostringstream ss;
    ss << format(gettext("This is the message to %1% about %2%")) % who % what;
    

    C++ using boost.locale:

    using boost::locale::format;
    using boost::locale::translate;
    std::ostringstream ss;
    ss << format(translate("This is the message to {1} about {2}")) % who % what;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Follow up to this question . I have the following code: string[] names =
Follow up to this question for Facebook Friends.getAppUsers using Graph API that pulls friends
As a follow up to this question , I have a parent entity that
I have been trying to follow the instructions in the answer to this question
I posted this question a few days ago, and I have some follow up
I have a follow-on question to the problem that the presence of overloaded method
Follow up to this question about GNU make : I've got a directory, flac
This question is a follow on from this one ... I am binding to
This question is kind of a follow up to this question I asked a
[a follow up to this question ] class A { public: A() {cout<<A Construction

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.