Re: LPCWSTR to CString conversion problem
Here is the minimalistic code in which i managed to reproduce the problem
HRESULT hr;
CComPtr<IStream> pFileStream;
CComPtr<IXmlReader> pReader;
XmlNodeType nodeType;
const WCHAR* pwszLocalName;
const WCHAR* pwszValue;
CString DownloadUrl;
CString total=_T("");
CString name,UVersion;
CString value;
ULONG i;
//Open read-only input stream
if (FAILED(hr = SHCreateStreamOnFile(_T("index.xml"), STGM_READ,
&pFileStream)))
{
}
if (FAILED(hr = CreateXmlReader(__uuidof(IXmlReader), (void**) &pReader,
NULL)))
{
}
if (FAILED(hr = pReader->SetProperty(XmlReaderProperty_DtdProcessing,
DtdProcessing_Prohibit)))
{
}
if (FAILED(hr = pReader->SetInput(pFileStream)))
{
}
while (S_OK == (hr = pReader->Read(&nodeType)))
{
switch (nodeType)
{
case XmlNodeType_Element:
hr = pReader->GetLocalName(&pwszLocalName, NULL);
break;
case XmlNodeType_Text:
hr = pReader->GetValue(&pwszValue, NULL);
if(!wcscmp(pwszLocalName,_T("release")))
UVersion = UVersion + pwszValue + _T(".");
if(!wcscmp(pwszLocalName,_T("webversion")))
UVersion = UVersion + pwszValue + _T(".");
if(!wcscmp(pwszLocalName,_T("url")))
{
//UVersion = "1280.56.";
for(i=0;i<UVersion.GetLength();i++)
{
if(_istdigit(UVersion.GetAt(i)) == FALSE)
{
AfxMessageBox(_T("digit not found"));
}
}
}
break;
}
}
///////////////////////////////////////////////////////////
The sample index.xml file looks like below...
<update>
<release>
1280
</release>
<webversion>
57
</webversion>
<url>
http://www.google.com</url>
</update>
////////////////////////////////////////////////////////////////
Here when i do UVersion.GetAt(i), the first element is a digit and the
messagebox must not pop up. But still i get the problem. If i uncomment the
line
//UVersion = "1280.56.";
then the code works correctly. Dunno where the problem lies. Hope the issue
gets recreated at your end. Please let me know if u need any other info.
Thanks,
Rohit
"SvenC" wrote:
Hi,
Since i am using an atl dll, i didnt need to include any additional
headers for using cstring. and when i press f12 in cstring, it goes to
afxstr.h
Could you provide a minimal but complete sample which shows the problem? The
code fragments you showed did not read the value attribute, only the name
attribute.
As stated before, when I modify the fragments to read the value attribute, I
have no problem in using isdigit(s.GetAt(i))
--
SvenC