help at MultiByteToWideChar
-
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
-
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
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.