Write Hex to Output File in MFC

Hi All:

I need to generate a file using MFC which is Unicoded. In 
other words, I need to have a file that has '16-bit hex 
coding' showing in the file when I open it thru notepad

Problem:
Even though I store the string in 16-bit format, when I 
write it into the file, it still displays it as ascii. I 
need to see '16-bit Hex' instead of the ascii. I am using 
the following code. The output in the file is "hello". 
Instead, I want to see "0x0048 0x0065 0x006C 0x006C 
0x006F".

I am using the following code. 

wchar_t rashid2[] =_T(L"Hello");
HANDLE hFile = CreateFile(_T("C:\\rashid\\FOO.lng"),
         GENERIC_WRITE, FILE_SHARE_READ,
         NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

CFile myFile(hFile);
myFile.Write(rashid2, wcslen(rashid2) * sizeof( wchar_t ));
myFile.Close();

I am using Visual Studio .NET. I appreciate any help.

Thanks,
Rashid Hameed (Annandale, NJ)
0
7/7/2003 7:19:19 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
846 Views

Similar Articles

[PageSpeed] 39

"Rashid Hameed" <hameedrashid@hotmail.com> wrote in message
news:038301c344bc$aa222250$a301280a@phx.gbl...
> Hi All:
>
> I need to generate a file using MFC which is Unicoded. In
> other words, I need to have a file that has '16-bit hex
> coding' showing in the file when I open it thru notepad

Notepad displays text, unicode or not. Either you want to write the text
"Hello" to your file (which in turn can be done using Unicode text or
ansi text) and you will see "Hello" when you open it with Notepad, or you
want to write the text corresponding to the hex representation of the 16
bit values of the Unicode text, and when you open it with Notepad you'll
see "0x0048 0x0065 0x006C 0x006C 0x006F".

If the latter, you need to convert the text in _T("Hello") to the text
corresponding to the hex values first, and then write that text to the
file.


-- 
jlr


0
jlr (33)
7/7/2003 8:08:42 PM
>
>If the latter, you need to convert the text in _T
("Hello") to the text
>corresponding to the hex values first, and then write 
that text to the
>file.
>

Do you know a function that can convert the 'text' 
to 'hex' values so that I can write hex values to the file?

Rashid.
0
7/7/2003 8:29:40 PM
Characters are binary integers. Print the binary integers in hex format. 

WCHAR test[] = L"Unicode Hello";

for(UINT i =0; test[i] != L'\0'; i++)
     { /* print it */
      CString s;
      s.Format(_T("0x%04x "), (WORD)test[i]);
      f.WriteString(s);
     } /* print it */
			joe

On Mon, 7 Jul 2003 13:29:40 -0700, "Rashid Hameed" <hameedrashid@hotmail.com> wrote:

>
>>
>>If the latter, you need to convert the text in _T
>("Hello") to the text
>>corresponding to the hex values first, and then write 
>that text to the
>>file.
>>
>
>Do you know a function that can convert the 'text' 
>to 'hex' values so that I can write hex values to the file?
>
>Rashid.

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
7/7/2003 9:28:47 PM
Thanks a bunch!!!....It solved my problem right away....

Rashid.

>-----Original Message-----
>Characters are binary integers. Print the binary integers 
in hex format. 
>
>WCHAR test[] = L"Unicode Hello";
>
>for(UINT i =0; test[i] != L'\0'; i++)
>     { /* print it */
>      CString s;
>      s.Format(_T("0x%04x "), (WORD)test[i]);
>      f.WriteString(s);
>     } /* print it */
>			joe
>
>On Mon, 7 Jul 2003 13:29:40 -0700, "Rashid Hameed" 
<hameedrashid@hotmail.com> wrote:
>
>>
>>>
>>>If the latter, you need to convert the text in _T
>>("Hello") to the text
>>>corresponding to the hex values first, and then write 
>>that text to the
>>>file.
>>>
>>
>>Do you know a function that can convert the 'text' 
>>to 'hex' values so that I can write hex values to the 
file?
>>
>>Rashid.
>
>Joseph M. Newcomer [MVP]
>email: newcomer@flounder.com
>Web: http://www.flounder.com
>MVP Tips: http://www.flounder.com/mvp_tips.htm
>.
>
0
7/8/2003 12:37:59 PM
Reply:

Similar Artilces:

Macro Help- combining "CS" files
Below is the macro I have to go to a certain file and combine all spreadsheets. I did not write this macro myself. I just received it and modified it to work for my situation. When this maco is run it gets to the first file and says I cannot change a read only file and says I must unprotect the worksheet. This sheet is not protected but I really only want to copy the info on it anyway. Is there a way to modify this macro to copy the information. I could save all of the "CS" files as new files but that would defeat the purpose of automating this job Any help is greatly a...

Is there a way for Windows Service to Read/Write HKCU Reg key ?
Hi: I'm writing a Windows Service program which needs to read/write the HKEY_CURRENT_USER registry key for the current logged on user. I know that for a Windows service does not have concept of HKCU since it is always running in SYSTEM's context. But is there a way (trick?) for a service to access the HKCU registry key? Thanks In Advance ! Polaris Hello Try, from a user application (the one that is logged on, or the current user), to send the services the user's SID. Then access the HKCU through HKEY_USERS\users_sid\............ Hope that helps, Elias "Polaris&qu...

Import data from DBF files
What's the best way to import a large dbf file into Access (records from a DBase file)? I have one dbf that has over 220,000 records in it. It gets to about 75% and says "The search key was not found in any record." Everything is patched to the max (Windows, Office, Jet, etc). This doesn't happen with any other dbf file, but they are all smaller. Also, oddly, I can copy and paste 50,000 records in a shot and paste them through a query, but I don't want to keep doing that for every large dbf I have. The Access tables have no problem holding the data, just transf...

"File not found" and "The form name is misspelled..." errors
I am still bulding a database. It contains no data, and contains no embedded macros. Yet, when I go to build code, I get these errors: "File not found" followed by "The form name * is misspelled or refers to a form the doesn't exist" The problem does not lie in the form that automatically opens when the database opens, and there are no embedded macros (I've read that these are the two main places an error such as this can occur). I did a search in the code box, and do find the two subforms listed even though neither contains any kind of code. I ca...

Write
I am trying to change the default margins. I am requested to use the Write mode to do this. What is Write, and how do I access it? Are you using voice recognition? Margins are simply changed in the Arrange Menu in Publisher. Are you in the right newsgroup? -- Mary Sauer MS MVP http://office.microsoft.com/ http://www.mvps.org/msauer/ news://msnews.microsoft.com "CBC" <anonymous@discussions.microsoft.com> wrote in message news:183bb01c44a40$107bd5d0$a501280a@phx.gbl... > I am trying to change the default margins. I am requested > to use the Write mode to do this. W...

pst files and VPN issues
I'm looking for suggestions on how to configure .pst files for remote users who access a network using VPN. Due to the large size of these files (often over a gigabyte), Outlook's performance is seriously affected and often freezes during the archive process. What are your company's polices for remote users accessing .pst files and is there a way short of saving them locally to access them without affecting Outlook's performance? If the .pst has to be stored and backed up locally, does anyone have security advice for protecting .pst files with sensitive material? Encrypted f...

Cannot open .msg files saved from Outlook to network share
Some of my users have dragged and dropped emails into their network shares creating .msg files. When they try to open some of the files they get the following popup: 'The messaging interface has generated an unknown error. If the problem persists, restart Outlook.' This only happens for some of the saved emails. They are using Outlook 2000 from Office. God only knows why they did this and didn't use autoarchive! How many training sessions does someone have to do?! Anyway, anyone know how I can open them or even better, why I cant? Regards Dave ...

Cannot write to memory location
I can not (all of the sudden) run Publisher in the last week. When starting to run it, I get that it cannot write to a certain memory locaiton, so it is shutting down. I need to get this program working. I have read through this forum and tried the different fixes as well as the knowledge base (emptied the temp file, disabled anti-virus, etc.) but it still won't work. An example is: "The instruction at "0x77f585c0" referenced memory at "0x00000000". the memory could not be "written". Click on OK to terminate the program." The header read...

Printing through MFC
Hi All, I want to print a html file through MFC application. How can i do this? I have bypass print dialog window. Thanks for your inputs. Regards, Manohar On 1 May 2007 23:21:28 -0700, Manu <manoharbasireddy@gmail.com> wrote: Hi Manohar, > I want to print a html file through MFC application. >How can i do this? I have bypass print dialog window. Thanks for >your inputs. you might consider using and embedded webbrowser control in your MFC app. You might Google for some code samples, e.g. on CodeProject. I found the following url: http://...

How to replace two system files?
I have an XP machine. Have just replaced a couple files from a W7 machine. The files are:- c:\windows\system32\drivers\disk.sys c:\windows\system32\drivers\partmgr.sys ....and now I can't boot the XP machine. How to get back to before I replaced the files? Thanks. "John Smith" <JohnSmith@nospam.com> wrote in message news:uLL8mqL0KHA.264@TK2MSFTNGP05.phx.gbl... > I have an XP machine. Have just replaced a couple files from a W7 machine. > The files are:- > c:\windows\system32\drivers\disk.sys > c:\windows\system32\drivers\partmgr.sys > ....

XSLT: Creating anchors from outer XML files
Hi, I'm trying to put the links (href attribute of the <a> element) out of my XSLT files, in a XML file, and read it from the stylesheet. I suppose that I have to use the document() function to link to the XML file containing the URLs, but I don't know how to do it. I've tried something like this: This is XML file containing the URLs (link.xml): <?xml version="1.0" encoding="utf-8" ?> <LINKS> <L1> /SomePage.aspx </L1> </LINKS> And this is the code from the stylesheet: <a href="{document('link.xml')/L...

write protect/write redirect/kios mode
Hey, I LOVE snapshots in virtualmachines and think it would be awesome to have something like this for my main windows install. Anyone know of any hardware/software to redirect writes to another drive/file/memory/hardware? Or hardware to write protect a drive for kios's (i found some once befor the reverted all changes on shutdown, but cant find it anymore ><) I know VSS(virtual shadow copy service) has a function to redirect on write and wondering if i might be able to use that :/ It will just make everything cleaner, and give alot of flexiblity to setting up ...

How to get the sectors/clusters of a particular file?
Hi, How to get the sectors/clusters of a particular file? I am working on Windows 2000. Hoping to get a reply soon. TIA. regards, Jahfer V P. No particular way I know of. If you have certain privileges you might be able to use DeviceIoControl(), but there isn't much you can do with this information. joe On Mon, 20 Jun 2005 23:33:02 -0700, "Jahfer V P" <JahferVP@discussions.microsoft.com> wrote: >Hi, > >How to get the sectors/clusters of a particular file? >I am working on Windows 2000. > >Hoping to get a reply soon. >TIA. > >regards, &g...

Validating Hyperlink for file
Hi, Is there a why to validate a list of hyperlinks to see if the file exists? The path is also what is show as the value in the cells in column D. Regards, Aaron ...

Missing OUTLLIB.DLL File
I have installed Outlook 2003 and receive error message, "Can't open application because the OUTLLIB.DLL is not found. I have re-installed but didn't fix my problem. Any suggestions? Nan <Nan@discussions.microsoft.com> wrote: > I have installed Outlook 2003 and receive error message, "Can't open > application because the OUTLLIB.DLL is not found. I have > re-installed but didn't fix my problem. > > Any suggestions? See your previous thread. No need to post more that once. -- Brian Tillman ...

converting .MP3 files to .AAC files
Is there a way to convert .MP3 files to .AAC files using Windos Media Player? I am trying to copy files to a SD card to play using a Nintendo DSI. Search online for a converter. Some are even free. "hjraymo" <hjraymo@discussions.microsoft.com> wrote in message news:1AA78C58-711F-412E-9F62-E87E81646083@microsoft.com... > Is there a way to convert .MP3 files to .AAC files using Windos Media > Player? > I am trying to copy files to a SD card to play using a Nintendo DSI. On Tue, 12 Jan 2010 07:42:01 -0800, hjraymo <hjraymo@discussions.microsoft.com...

How can I resize/restore the File > Save As window?
Somehow I have managed to expand the File | Save As window such that it now fills the whole screen. This only affects Excel (2007). There is no minimise button, and I cannot see the bottom RH corner to grab it and resize the window and I cannot get hold of any edge of the window to move it. How can I resize/restore the File > Save As window? TIA. Chris. Try double-click on the Title Bar Gord Dibben MS Excel MVP On Fri, 4 Dec 2009 16:18:15 -0000, "Chris Mitchell" <chris.a.mitchell@NOSPAMbtinternet.com> wrote: >Somehow I have managed t...

Circumvent password on recovered .asd file
On a computer with Word 2007 SP2 running on Windows XP SP3: Word quit unexpectedly for one of our users yesterday and it saved an auto-recovered file to her profile in the C: drive. When she tries to open the .asd file, it prompts her for a password. The original file did not have a password. Does anyone know a way to get around the password besides buying a password-cracker? Thank you. Far more likely is that the document is corrupt. Passwords don't get added willy nilly. If it was saves as a .doc file, try the Open and Repair option or try opening it in Wordpad. If i...

Edb and Stm Database File Maintenance
I am trying to observe and understand the changing status of the edb and stm files during a controlled and simulated flow of mail into both the private and mail enabled public folders. 1 Is there any circumstance where the size of these four database files would be reduced during the scheduled on-line maintenance. (I know that off-line compression will reduce these file sizes, but what about on-line processes)? 2 What processes cause a transfer of data from the stm to the edb database? 3 The application log tells me that every 15 minutes during the maintenance window there is a check by the...

fatal error LNK1104: cannot open file 'mfc71.lib'
I have a project that was built with VS 2003. After doing the auto conversion with VS 2005, I now get this error message when linking: fatal error LNK1104: cannot open file 'mfc71.lib' There is only one .cpp file in this project. There is no reference to MFC71.lib in the project. Any ideas? > I have a project that was built with VS 2003. After doing the auto > conversion with VS 2005, I now get this error message when linking: > > fatal error LNK1104: cannot open file 'mfc71.lib' > > There is only one .cpp file in this project. There is no reference to &g...

Temp file folder?
I'm using xp and OE6 I d/l'd aWHOLE bunch of encoded mp3files. During the compile and decode process my pc crashed. I suspect I have a WHOLE bunch of temp files somewhere. that I want to clean up. Any idea as to their location? Regards, Lawrence L Mossford <lmossford1@shaw.ca> wrote: > I'm using xp and OE6 Wrong newsgroup. > I d/l'd aWHOLE bunch of encoded mp3files. During the compile and > decode process my pc crashed. I suspect I have a WHOLE bunch of temp > files somewhere. that I want to clean up. Temporary Internet Files, perhaps? -- Brian...

Writing formula for excel worksheet
Item Rate1 Rate2 Rate3 A 3 4 6 B 8 5 23 C 56 5 78 Above is my excel sheet. I want to write some formula so that in every row cell having minimum rate should come bold. Like For Item A - Rate1(3) for Item B - Rate2(5) For Item C - Rate2 (5) There may be a neater way but this works. Somewhere in you sheet in a cell type =min(A1:a4), I used L1 Change this to watever range you are trying to evaluate. Then select this range and click format - conditional format - cell value - is equal to =($L$1) and apply your bold font. The lowest value in the range will then become bold. Mike "Gaur...

how do i write checkbox to.....
This is a multi-part message in MIME format. --------------050607000103070200020407 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit how do i write checkbox1 boolean to xml in vb6 i can only do cstr( checkbox1.value) but in vb.net can't write to xml. i am doing irc chat similar to mirc or pirch chat. rw.WriteConfigInfo("User Modes", chkInvisible.Text, chkInvisible.Checked, "PirateChat.xml") in procedure events: ' Both the Key and the Value are filled ' Find the key ...

deleting temp web files
When I delete the temporary internet files with the Iexplorer menu of Tools->InternetOptions->General->DeleteFiles Does this delete said files only for the current User account logged on? Or does it delete said files for all user accts on machine ? Just the current user I think. neil "RB" <NoMail@NoSpam> wrote in message news:#FNlBGX3KHA.1016@TK2MSFTNGP02.phx.gbl... > When I delete the temporary internet files with the Iexplorer menu of > Tools->InternetOptions->General->DeleteFiles > Does this delete said files only for the current...

Money 2005 will not automatically import .ofx files
At one time, when I downloaded my bank statement as a .ofx file, money automatically imported it and showed the transactions. It no longer does this. I have to select file>import and find the file. I cannot find any settings to change this. Any ideas? Paul On Mon, 23 Nov 2009 11:59:06 -0000, "Paul Fearnley" <paul@pdfearnley.demon.co.uk> wrote: >At one time, when I downloaded my bank statement as a .ofx file, money >automatically imported it and showed the transactions. It no longer does >this. I have to select file>import and find the file. ...