Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. help at MultiByteToWideChar

help at MultiByteToWideChar

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionwcfxmltutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    monsieur_jj
    wrote on last edited by
    #1

    Hi all, I need your help in my code I got from the gsoap article of Dr. Luigi here is his code:

    CString CMyCurrencyConvertor::GetSoapError()
    {
    struct soap *pSoap = m_pCurrencyConvertor->soap;
    CString sError;
    if (soap_check_state(pSoap ))
    sError.Format("Error: soap struct not initialized\n");
    else
    {
    if (pSoap->error)
    {
    const char *pFaultCode, *pFaultSubCode = NULL, *pFalutString,
    **iFaultCode;
    iFaultCode = soap_faultcode(pSoap );
    if (!*iFaultCode)
    soap_set_fault(pSoap );
    pFaultCode = *iFaultCode;
    if (pSoap ->version == 2)
    pFaultSubCode = *soap_faultsubcode(pSoap );
    pFalutString = *soap_faultstring(pSoap );
    iFaultCode = soap_faultdetail(pSoap );
    sError.Format("%s%d fault: %s [%s]\"%s\"Detail: %s",
    pSoap->version ? "SOAP 1." :\
    "Error ", pSoap->version ? (int)pSoap->version : pSoap->error,
    pFaultCode, \
    pFaultSubCode ? pFaultSubCode : "no subcode",
    pFalutString ? pFalutString : "[no reason]", \
    iFaultCode && *iFaultCode ? *iFaultCode : "[no detail]");
    }
    }
    return sError;
    }

    Now as per his advise is used MultiBytetoWideChar as the sError being returned is in japanese/chinese. I modified his code into this:

    sError.Format(_T("%s%d fault: %s [%s]\"%s\"Detail: %s"),
    pSoap->version ? "SOAP 1." :\
    "Error ", pSoap->version ? (int)pSoap->version : pSoap->error,
    pFaultCode, \
    pFaultSubCode ? pFaultSubCode : "no subcode",
    pFalutString ? pFalutString : "[no reason]", \
    iFaultCode && *iFaultCode ? *iFaultCode : "[no detail]");

    MultiByteToWideChar( CP_ACP, 0, CT2A(sError),
    strlen(CT2A(sError))+1, wszFaultString,
    sizeof(wszFaultString)/sizeof(wszFaultString[0]) );

    Now my problem is that once it is converted instead of the words i am expecting i get question marks example is fault: ????? but it should be fault: host not found. What should I do? Thanks, Jayjay

    I 1 Reply Last reply
    0
    • M monsieur_jj

      Hi all, I need your help in my code I got from the gsoap article of Dr. Luigi here is his code:

      CString CMyCurrencyConvertor::GetSoapError()
      {
      struct soap *pSoap = m_pCurrencyConvertor->soap;
      CString sError;
      if (soap_check_state(pSoap ))
      sError.Format("Error: soap struct not initialized\n");
      else
      {
      if (pSoap->error)
      {
      const char *pFaultCode, *pFaultSubCode = NULL, *pFalutString,
      **iFaultCode;
      iFaultCode = soap_faultcode(pSoap );
      if (!*iFaultCode)
      soap_set_fault(pSoap );
      pFaultCode = *iFaultCode;
      if (pSoap ->version == 2)
      pFaultSubCode = *soap_faultsubcode(pSoap );
      pFalutString = *soap_faultstring(pSoap );
      iFaultCode = soap_faultdetail(pSoap );
      sError.Format("%s%d fault: %s [%s]\"%s\"Detail: %s",
      pSoap->version ? "SOAP 1." :\
      "Error ", pSoap->version ? (int)pSoap->version : pSoap->error,
      pFaultCode, \
      pFaultSubCode ? pFaultSubCode : "no subcode",
      pFalutString ? pFalutString : "[no reason]", \
      iFaultCode && *iFaultCode ? *iFaultCode : "[no detail]");
      }
      }
      return sError;
      }

      Now as per his advise is used MultiBytetoWideChar as the sError being returned is in japanese/chinese. I modified his code into this:

      sError.Format(_T("%s%d fault: %s [%s]\"%s\"Detail: %s"),
      pSoap->version ? "SOAP 1." :\
      "Error ", pSoap->version ? (int)pSoap->version : pSoap->error,
      pFaultCode, \
      pFaultSubCode ? pFaultSubCode : "no subcode",
      pFalutString ? pFalutString : "[no reason]", \
      iFaultCode && *iFaultCode ? *iFaultCode : "[no detail]");

      MultiByteToWideChar( CP_ACP, 0, CT2A(sError),
      strlen(CT2A(sError))+1, wszFaultString,
      sizeof(wszFaultString)/sizeof(wszFaultString[0]) );

      Now my problem is that once it is converted instead of the words i am expecting i get question marks example is fault: ????? but it should be fault: host not found. What should I do? Thanks, Jayjay

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      You have a few diagnostic tools... Try putting wszFaultString,su into the watch window to see the wide string. (I assuming you are debugging this line by line? If not, don't come back until you have) Also, you can view each unicode character individually, and see if the characters are being converted accurately (compare contrast with charmap) and visual studio is just having japanese font rendering problems, or even your app is displaying the text in a font that is missing those characters... You're not checking the response from MultiByteToWideChar - are you sure it is succeeding? What's with the CTO2A macro? If you're doing an explicit conversion, shouldn't you handle it yourself? That way you can see the intermediate results... Good luck, Iain.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups