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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:11:09+00:00 2026-05-16T10:11:09+00:00

I am using some cross platform stuff called nutcracker to go between Windows and

  • 0

I am using some cross platform stuff called nutcracker to go between Windows and Linux, to make a long story short its limited in its support for wide string chars. I have to take the code below and replace what the swprintf is doing and I have no idea how. My experience with low level byte manipulation sucks. Can someone please help me with this?

Please keep in mind I can’t go crazy and re-write swprintf but get the basic functionality to format the pwszString correctly from the data in pBuffer. This is c++ using the Microsoft vc6.0 compiler but through CXX so it’s limited as well.

The wszSep is just a delimeter, either “” or “-” for readabilty when printing.

HRESULT BufferHelper::Buff2StrASCII( 
   /*[in]*/ const unsigned char * pBuffer, 
   /*[in]*/ int iSize,
   /*[in]*/ LPWSTR wszSep,
   /*[out]*/ LPWSTR* pwszString )
{
 // Check args
 if (! pwszString) return E_POINTER;

 // Allocate memory
 int iSep = (int)wcslen(wszSep);
 *pwszString = new WCHAR [ (((iSize * ( 2 + iSep )) + 1 ) - iSep ) ];
 if (! pwszString) return E_OUTOFMEMORY;

 // Loop
 int i = 0;
 for (i=0; i< iSize; i++)
 {
  swprintf( (*pwszString)+(i*(2+iSep)), L"%02X%s", pBuffer[i],  (i!=(iSize-1)) ? wszSep : L"" );
 }
 return S_OK;
}

This takes whats in the pBuffer and encodes the wide buffer with ascii. I use typedef const unsigned short* LPCWSTR; because that type does not exist in the nutcracker.

I can post more if you need to see more code.

Thanks.

  • 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-16T10:11:10+00:00Added an answer on May 16, 2026 at 10:11 am

    It is a bit hard to understand exactly what you are looking for, so I’ve guessed.

    As the tag was “C++”, not “C” I have converted it to work in a more “C++” way. I don’t have a linux box to try this on, but I think it will probably compile OK.

    Your description of the input data sounded like UTF-16 wide characters, so I’ve used a std::wstring for the input buffer. If that is wrong, change it to a std::vector of unsigned chars and adjust the formatting statement accordingly.

    #include <string>
    #include <vector>
    #include <cerrno>
    #include <iostream>
    #include <iomanip>
    #include <sstream>
    
    #if !defined(S_OK)
        #define S_OK 0
        #define E_OUTOFMEMORY ENOMEM
    #endif
    
    unsigned Buff2StrASCII( 
                    const std::wstring &sIn, 
                    const std::wstring &sSep, 
                    std::wstring &sOut)
    {
        try
        {
            std::wostringstream os;
    
            for (size_t i=0; i< sIn.size(); i++)
            {
                if (i)
                    os << sSep;
                os  << std::setw(4) << std::setfill(L'0') << std::hex
                    << static_cast<unsigned>(sIn[i]);
            }
            sOut = os.str();
            return S_OK;
        }
        catch (std::bad_alloc &)
        {
            return E_OUTOFMEMORY;
        }
    }
    
    
    int main(int argc, char *argv[])
    {
        wchar_t szIn[] = L"The quick brown fox";
        std::wstring sOut;
        Buff2StrASCII(szIn, L" - ", sOut);
        std::wcout << sOut << std::endl;
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing cross platform(Windows, Linux) desktop application using Mono and Gtk#. Application will
For some time now I've been happily using dlmalloc for a cross-platform project (Windows,
I am doing some cross-platform work, porting code from Linux to Win32, but when
I'm working on some cross-platform code using OpenGL and SDL, but have immediately run
Possible Duplicate: Cross platform programming I've written some code using wxwidgets in c++. But
Doing cross platform development with 64bit. Using gcc/linux and msvc9/server 2008. Just recently deployed
I am writing application in C# using GTK# GUI framework to make it cross-platform.
I'm drawing some text in Mac/iOS cross-platform code using CoreText. I may be using
I built some cross fade rollovers in IE7 using this single image technique: http://jqueryfordesigners.com/image-cross-fade-transition/
I am trying to use appcelerator to develop some cross platform mobile applications, but

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.