save string as unicode

This problem is solving itself piece by piece. I have a legacy VC 6 application and have to fix it to produce a unicode file.
By turning on 'see display unicode string option on under tools/options/debug' I now know that the string I have actually does have the unciode entity.  But the routine used bty the application to save any strings is not working correctly - it saves the unicode as ?.

Can anyone show me a very simple code snippet to do this !  I know there is information about settiings...I need to be able check this large application for the settings, ( help please ), drop in the snippet, then go back and see why/if the existing file save code is failing. ( I need to fix the existing one if my settings are correct  - because of the extensive business logic the application does to the strings(s) that form the file.  Thanks Andrew
0
andrewcw (18)
4/14/2004 1:11:07 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
478 Views

Similar Articles

[PageSpeed] 39

Hi Andrew,

>But the routine used bty the application to save any strings is not 
working correctly - it saves the unicode as ?.
>
Do have checked its binary code? Maybe the Unicode string has already been 
saved, but the file is not saved as an Unicode txt file. (If a txt file's 
first 2 bytes is 0xFF and 0xFE��it is Unicode file��else it is an ANSI txt 
file.) 

What's routine do you use to save the Unicode string?
How about copy the Unicode string into a TCHAR array first, then save the 
TCHAR array to the target file:
TCHAR szBuffer[MAX_LENGTH];
_tcscpy(szBuffere, (LPCTSTR) szUnicode);


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

0
v-garych (605)
4/15/2004 9:50:54 AM
I tried this but content did not have the enity ( small delta ) I expected. The file looks the same - although I inspected the
memory location of cstrHTML . Is there some other value(s) that need to be in place ???  Thank

CString cstrHTML(bstrHTML)
CFile		fOutFile
CFileException	exception
int		status

const int MAX_LENGTH=20000
TCHAR szBuffer[MAX_LENGTH]
_tcscpy(szBuffer, (LPCTSTR) cstrHTML);
CString htmlPath
htmlPath = "c:\\delta.html"
status = fOutFile.Open(htmlPath,
CFile::modeCreate | CFile::modeWrite | CFile::shareExclusive, &exception)
fOutFile.Write ( szBuffer,  cstrHTML.GetLength())

0
andrewcw (18)
4/15/2004 6:06:12 PM
Hi Andrew,

Do you have checked the following MSDN doc:
Unicode Topics
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HT
ML/_core_unicode_topics.asp

Strings: Unicode and Multibyte Character Set (MBCS) Support
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HT
ML/_core_strings.3a_.unicode_and_multibyte_character_set_.28.mbcs.29_.suppor
t.asp

I think you may not  have a Unicode versions of the MFC libraries 
installed, the Unicode versions of the MFC libraries are not copied to your 
hard drive unless you select them during a Custom installation. 


Wish it helps!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

0
v-garych (605)
4/16/2004 9:04:24 AM
You are right, unicode MFC is not the default in VC6 ++ and if you had not told me I would never have kept selecting the options - it was really deeply nested

As for seeing if I should use unicode or isolate it or do all this specific task work in TCHAR ... I don't know - I summerized the facts and now other big-cheeses can decide. Thanks for the many replies and help ! 
0
andrewcw (18)
4/17/2004 1:41:04 AM
Reply:

Similar Artilces:

Serialize class to string?
How do you use the XmlSerializer to serialise a class instance to a string as opposed to a file or stream? Thanks Ben Fidge was answered for example in this thread [0] -- HTH Christoph Schittko [MVP] Software Architect, .NET Mentor [0] http://dbforums.com/arch/73/2002/10/516420 "Ben Fidge" <ben.fidge@btopenworld.com> wrote in message news:#007uUmxDHA.2304@TK2MSFTNGP12.phx.gbl... > How do you use the XmlSerializer to serialise a class instance to a string > as opposed to a file or stream? > > Thanks > > Ben Fidge > > ...

pulling certain characters from a string of text
I need to look up "certain critera" within a string of characters, then return that "certain criterea" to a new column. Some examples of a strings of characters may look like these: K5J091509001 Sample PO#S881009 K55sample PO CarrieRJR TJ5 My "Certain Critera" I have listed on another sheet, named "REP ID" K5J S88 K55 RJR TJ5 How do I pull out the 3 characters of "Certain Criterea" from the string of text and copy or enter it into a new column? Hi, =left(a1,3) "SaraMack" wrote: > I need to look up "c...

Saving to HTML in Publisher 98
How do I save all pages at once to HTML rather than one page at a time. This seems so long winded, and if I just do it once then most of the links do not work. The upgrade to Pub 2003 is worth it. P. "Ian Pengelly" wrote: > How do I save all pages at once to HTML rather than one page at a time. This > seems so long winded, and if I just do it once then most of the links do not > work. ...

How to know if a brand new transaction has been saved
Hello to all, When a user opens a screen, for example Payables Transaction Entry, a new Voucher Number is displayed on the form but, since the user hasn't typed anything else on the screen, the changed() function returns false. What I need is the following: a) When the form opens, run the forche changes method, how do I do that? b) If the user selects an existing transaction, run the clear changes method, how do I do that? -- Best regards, Sergio Romero Exactly what are you trying to do? Normally, you can check the 'Display Existing Record' field to see if the transaction...

Return string of values from range
Is it possible to return string of values from range instead of the range in a formula. In the following formula I need to reference the names "FruitList and VegetableList" (which are list headings) CHOOSE(MATCH(A2&"List",ListRng),FruitList,VegetableList) this works but I need the headings to be dynamic in the formula I defined a name "Cat1List" to the location of those list headings. and tried CHOOSE(MATCH(A2&"List",ListRng),Cat1List) CHOOSE just picks up the the range of the name instead of the two values. Is ther a function or method to re...

Excel changes macros when saving as pdf
Last week I had no problem saving my financial macros enable spreadsheet as a pdf. Now, forget it! It won't let me do anything...print, copy, cut, past, save as pdf, NOTHING without several of the worksheets changing the numbers to text tht says "VALUES" across the whole line. When Adobe opens the file, it says that my macros is unenabled when it is, and it lst's the "fixes" you're supposed to do in order to get it to work...which I've done over and over again. The security settings are correct and I've been over it countless times. I ...

Looping Open and Save as CSV
I have to open worksheets and then save them as CSV files for another program. When I used the macro recorder, it copied the entire path so that when I run macro is puts the file back in the same folder every time regardless of path for the XLS file. All the file names are VOLUME, but the path changes for the various options. How do I edit the macro below to get it to save XLS files as CSV files in the same directory that the XLS file cam from instead of the one where I initially recorded the macro? Active..SaveAs Filename:= _ "Y:\Yarger Engineering\20090802\Syn...

How to populate a dataset from an XML formated String
Hi there Here's my question : I'd like to populate a dataset from an XML string, ie: Dim sXmlString As String sXmlString = "<root type='E-Form'><question label='This is my first question'></question><question label='This is my second question'></question></root> Any idea to achieve this ? Thanks in advance, J.Philippe Sure... :) Take a look at the System.IO.StringReader and the DataSet.ReadXml Method.. Source code is from the following link: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/h...

Data not saved in contact
I enter some info intp the Department field (Business tab)of any contact, save and close it. When I come to open this contact Department field is empty. It happens to all contacts , but only with this field. I have Outlook XP with POP3 account. Thank you Lilia ...

savings planner
:confused: lets say i need to save �1500 from now over the next 1 months. i want a tempate that when i add the ammount i save each week whic will vary it will update how much i have saved and how much i stil need to put away. the chart might if possible also be able to tell me what i need to sav on average to get to my target a long shot i know but someone must be able to help me out many thanks chri -- chrisscot ----------------------------------------------------------------------- chrisscott's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1566 View this t...

Error message when I save the changes to security roles
Hi I met a problem. When I try to save the changes to a security role, the system always gives me an error message I attached. Sometimes, the changes are made. Sometimes, not. Does anybody have idea? Thanks in advance. Rich Server Error in '/' Application. ----------------------------------------------------------- --------------------- Request timed out. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: S...

saving work
why is it that when I go to save a workbook, excel offers to stick it in some bizare folder in user/data/identity/temp/ iecontent/blah blah the folder is then labeled with mysterious digits and letters... I never choose to put it there but this strange place exists... don't really know why . thanks Dave tools>options>general>default file location -- Don Guillett SalesAid Software donaldb@281.com "D" <post@siteplease> wrote in message news:uP5U7aFYEHA.2140@TK2MSFTNGP11.phx.gbl... > why is it that when I go to save a workbook, excel offers to stick it in >...

saving report
I have a report with 600 pages...each page for a different client. Is there a way to have Access automatically save each page as a separate report? I would want each page saved using the client name field. -- Message posted via http://www.accessmonster.com "dhoover via AccessMonster.com" <u26355@uwe> wrote > I have a report with 600 pages...each page for > a different client. Is there a way to have Access > automatically save each page as a separate > report? I would want each page saved using > the client name field. I don't understand what...

Outlook Express saving JPG attachments correctly
I have recently down loaded the Microsoft Outlook Express Upgrade from 5.0 to 6.0 and I have lost the option to save attached JPG files as a as JPG file they default saving extension to a NWS file extension which is not acceptable to my editor. Is this a known problem and or is there an easy fix? this is a big problem and is part of Microsoft's idea for security control. it is not just jpegs that you can not attach. You can not attach any files, without changing their extension, as I have the same problem. Bill Gates gets to decide what you can and can not attach - not you! T...

Why do PDF attachments in OWA 2003 need to be saved before opening?
Hello, When our users try to open PDF attachments in a default E2K3 OWA installation, they are prompted to save it before opening. Is there any way to prevent that and allow them open it directly please? They can do that with Word attachments, for example. PDF isn't mentioned in the Level1 or Level2 lists. And what's annoying is that if they right-click on the attachment, then one of the IE options is "Open" anyway. Go figure. Thanks, - Alan. I believe that with Word documents they're saving the document but just aren't being prompted for it. The...

Extracting text from a string.
Hello, Is there a way for excel to extract a snippet of data from a text string? For the following string, Form:FOUR:OL_FRYEN:00:Text:ON I want to extract the data between the 2nd and 3rd colons, so the result should be: OL_FRYEN The data is always in Column A, so ideally, the extracted bit would be entered beside the source string, in Column B. Each tab (268 of them) in my spreadsheet/workbook has anywhere between 30 to 6000 lines, and I want to extract the data between the 2nd and 3rd ":" in each case. I started to do this using a formula but it quickly got very cumbe...

Detect Difference Between Autorecover and Save
I am trying to detect different kinds of Save. I know the difference between Save and Save As, but how can I detect the difference between them and Words Autorecover Save? ...

Store start/finish automatically before file save?
I am working on a quite large project, which is to be devided in several logical parts. For each part there is a seperate project-file and where necessary there are cross-project-links between tasks of the different files. At last all seperate sub-project files have a series of important milestones to be monitored in the master project file, where all sub- project files are inserted as linked projects. In the master project file each sub-project milestone is linked to a kind of 'commission milestone', all with a Must Start On of Must Finish On constraint to be referred to....

Getting the longest string?
XML <data> <option>this is test 1</option> <option>this is test 11</option> <option>this is test 111</option> <option>this is test 1111</option> <option>this is test 11111</option> </data> The 5 option has the longest content. I need to get that length and place in a variable. The test has to look across all of the option nodes and return the longest one. Any suggestions? Cheers Keith Sample code static void Main(string[] args) { System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc....

How do I import my saved email from a pst file to my inbox?
I do what it says but it does not show up in my inbox. Help! fkb <fkb@discussions.microsoft.com> wrote: > I do what it says but it does not show up in my inbox. Help! Click File>Open>Outlook Data File, browse to the PST, select it, and click OK. You'll now have access to the data it contains, provided it's not corrupt. After that, drag-and-drop or right-click>Copy to move your data from the added PST to your Inbox. -- Brian Tillman ...

URL type string field 'hack' in 3.0 possible?
Hi all, Our client had a requirement in 1.2 to have a field of type URL that would bring up a Windows Explorer window when clicked. For example, the URL field would contain the string "file:///C:\Customers". When doubled click it would display an Explorer window with the folder location to C:\Customers in a new window. When trying to duplicate this in 3.0, there is a pop up that displays, "Invalid protocol. Only HTTP and HTTPS are allowed in this field". I've tried searching all CRM specific javascript files in the file system to see if there is an occurrence to thi...

unable successfully save settings on ie7 after upgrade from ie6
Appreciate any helpful advice on subject matter. TIA win xp pro sp3 franktee A blank Web page is displayed when you start IE7 [ignore the title] http://support.microsoft.com/kb/945385 When you open IE7, it may default to [the Welcome or Customize Your Settings] page http://www.winhelponline.com/blog/fix-ie-runonce3-aspx-every-startup/ Those with IE7- and/or IE8-specific questions or comments can post to and seek support in IE General newsgroup: microsoft.public.internetexplorer.general On the web: http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=mic...

GetProcAddress Ansi/Unicode?
I am experimenting with the new Vista API TaskDialogIndirect with this code: HMODULE h = ::LoadLibrary( _T("comctl32.dll") ); FARPROC func = GetProcAddress(h,"TaskDialogIndirect"); GetProcAddress() returns NULL in ANSI builds, and a valid pointer in UNICODE builds. After a while I found that TaskDialogIndirect is only documented to work in UNICODE. But how can GetProcAddress() know that the calling program is not UNICODE? Best regards, Petter "Petter" <petter@nospam.nospam> wrote in message news:enBlml29HHA.5164@TK2MSFTNGP05.phx.gbl... >I ...

Powerpoint 2007 bug: add clipart, exit, does not prompt for save
Open an existing slide in Powerpoint. Do NOTHING but add clipart. Hit red X to exit app. Does NOT prompt for save, and change to slide is not saved. So far have only had this issue with adding clipart to a slide. Has anyone else seen this? Is there a bug fix available? Seeing in PP2007 with SP1 and SP2. Hmmm, I just tried to repro and was prompted to save. - open PPT 2007 (SP2) - INSERT >> INSERT CLIPART - Added a generic (vector) clipart from MS offering - Click 'x' to close PPT - Prompted to save changes Question: what OS are you running and is it 32 or 64-bi...

CString
Hello: I have been working on very large cstrings - maximum length goes upto around 750000. I am working on a 1 GB RAM machine and i have the following problem in a portion of the code. CString abc; while(blah blah) { abc += xyz; } At some point (though it is different everytime i run, around length of 500000 + ), the concatination statement crashes (consistently as unhandled exception) and the call stack leads me to the allocbuffer statement in cstring (where in turn it seems to fail on the new handler) My questions: 1) Viewing the task manager, I can say that the full RAM is not ut...