473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

File operation problem

i am trying to give my XML parsing code UNICODE support. if UNICODE is not defined it works fine. but if i define it it gives some garbage values. (i am showing it in mag box) the problem is in the

dwFileRead = static_cast<DWORD>(fread(ptempXML, sizeof(TCHAR), dwFileSize, pfTempXMLBuf));
statement. what are the changes i have to make in the code. the file successfully comes in pfTempXMLBuf. but ptempXML shows garbage.



pfTempXMLBuf = _tfopen(tcsBufXMLFileName, _T("w+"));

m_pNode->Print(pfTempXMLBuf, 0);
fseek(pfTempXMLBuf,0, SEEK_SET);
dwFileSize = _filelength(fileno(pfTempXMLBuf ));
ptempXML = new TCHAR[dwFileSize + 1];
if(ptempXML)
{
memset(ptempXML, 0, dwFileSize); // Required otherwise ending char are junk.
fseek(pfTempXMLBuf,0, SEEK_SET);
dwFileRead = static_cast<DWORD>(fread(ptempXML, sizeof(TCHAR), dwFileSize, pfTempXMLBuf));
ptempXML[dwFileRead] = _T('\0'); // Required as the file size is most larger then the actual file contain read which appends junk at end.
rc = ptempXML;

delete []ptempXML;
}
May 10 '07 #1
1 1587
weaknessforcats
9,208 Expert Mod 8TB
You might read up on using fseek with wide characters. I believe that due to particular multibyte encoding rules that you can get wrong results from fseek. If memory serves, you are supposed to use fgetpos() and fsetpos() with wide characters.
May 10 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Kevin | last post by:
Has anyone else run into random IOErrors ( bad file descriptor) in multi-threaded Python apps? I've searched the newsgroups, and the only references I can find to that seem to be sporadically...
0
by: suresh | last post by:
Hello All, Iam writing a wsdl file using the Servicedescription class.The document I get is a well formed xml document.But some how when I try to add this wsdl file as a webrefernce to another...
9
by: Vai2000 | last post by:
Hi All, Here's a situation, I am trying to process some large Files via a Win Svc using FileMonitor. During the test process I tried copy and pasting a file in a folder and got an error saying...
1
by: moonriver | last post by:
In a xml file, can we make reference to another xml file so that all contents of the latter xml file will be included into the first xml file? Had better give me an example for details.
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
32
by: Olivier | last post by:
Dear all, I thought the code ----------------------------- pt_fichier_probleme = fopen(nom_fichier, "w"); if(pt_fichier_probleme == NULL){ message_warning_s ("Erreur l'ouverture du...
0
by: jfigueiras | last post by:
>I have a problem with the module subprocess! As many other programs... I'm not sure what you mean by "non-standard file descriptors". The other program is free to open, read, write, etc any...
2
by: scriptlearner | last post by:
OS: Solaris 9 Python Version: 2.4.4 I need to log certain data in a worker thread; however, I am getting an error now when I use two worker threads. I think the problem comes from the line...
15
by: =?ISO-8859-15?Q?L=E9na=EFc?= Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all, For some reasons, somewhere in a program, I'd like, if possible, to quickly parse a whole file before rewinding it and letting the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.