strcpy not work in Unicode mode

Hi all,

i have a var with TCHAR type, like that

TCHAR sz[MAX_PATH];

// ...
strcpy(sz, "Hello");
// ...

it get error ? How to fix it?

Thanks


0
duy.trinh (99)
11/4/2006 4:57:03 AM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
714 Views

Similar Articles

[PageSpeed] 49

Use _tcscpy instead. Also use _T prefix, eg _T("hello"). Keep in mind that
using CString for this kind of work is much easier.

-- 
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com


"Duy Trinh (Mr.)" <duy.trinh@mobinex.com> wrote in message
news:ubL4r28$GHA.4844@TK2MSFTNGP02.phx.gbl...
> Hi all,
>
> i have a var with TCHAR type, like that
>
> TCHAR sz[MAX_PATH];
>
> // ...
> strcpy(sz, "Hello");
> // ...
>
> it get error ? How to fix it?
>
> Thanks
>
>


0
ajaykalra (6842)
11/4/2006 5:18:39 AM
Well, I should HOPE it gets an error!  strcpy will try to copy 8-bit characters, and it is
trying to copy them to a 16-bit character target, and therefore the compiler quite rightly
complains.  

Generally, you want to avoid using TCHAR arrays except in some VERY rare and exotic
conditions.  Use CString.

CString sz = _T("Hello");

would be the best solution.  

In addition, although you could use _tcscpy (which compiles as strcpy in 8-bit mode and
wcscpy in Unicode), such dangerous and obsolete constructs should be avoided.  Use the
strsafe.h library (StringCchCopy) or the new _tcscpy_s call in VS.NET 2005.  

All string and character literals should use the _T() macro, e.g., _T("Hello"), _T('a') so
you get Unicode literals.
					joe

On Sat, 4 Nov 2006 11:57:03 +0700, "Duy Trinh \(Mr.\)" <duy.trinh@mobinex.com> wrote:

>Hi all,
>
>i have a var with TCHAR type, like that
>
>TCHAR sz[MAX_PATH];
>
>// ...
>strcpy(sz, "Hello");
>// ...
>
>it get error ? How to fix it?
>
>Thanks
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
11/7/2006 12:06:01 AM
Reply:

Similar Artilces:

How to Restrict Users to view/go to Query Design/Sql mode in MDE/M
I want to secure my Access MDE file so that My users can not go to Design / SQL view of the query. Currently after opening query through command button provided by me on form , any user can press right click button & Go to design/Sql view of the query & fiddle with it. I want to keep enable right click mouse button but disable "Query Design" option. Like for forms & reports design option is not available after creation of MDE file. I am not in a position to use Security & group wizard provided by Access. Please Guide. Thanks . Girish Disabled the default short...

Back and foward buttons do not work in XPSp3
I recently did a system restore point on my windows xp Sp3 machine since I had some issue. The computer is clean from any virus. I noticed that in in folder of the tool bar, the back or fowad button does not work. The buttons of the foward and back are grayed out and do not function. I have to use the up arrow button to go back to where I was. This has been frustrating me all day. I am open to hearing from anyone who can provide me a fix on how to repair the back and foward buttons. RussellA "Russell Ashenberg" <neshoma@bezeqint.net> wrote in messa...

Re: VBscript works normally on Windows XP/Win2003 but not on Win Vista -> "Invalid class" error
"Estefania" <Sant merdir> escribi� en el mensaje de noticias:... > > > "Estefania" <Sant merdir> escribi� en el mensaje de > noticias:F45434D2-7809-4C21-B06F-B2EEA3026A3C@microsoft.com... >> >> >> "Estefania" <Sant merdir> escribi� en el mensaje de >> noticias:EE6921A8-5D3D-42B6-AE35-58B998ED4262@microsoft.com... >>> >>> >>> "Nick Dakoronias" <dakoroni@gmail.com> escribi� en el mensaje de >>> noticias:AF5BC5A9-873A-447E-9FD4-F75E0F89655D@mic...

i have microsoft works spreadsheet not excell, can i upgrade to ex
Can I upgarde or do i need to buy the full version? There's upgrade eligibility information on the Microsoft site: http://www.microsoft.com/office/editions/howtobuy/standard.mspx Anne wrote: > Can I upgarde or do i need to buy the full version? -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html ...

C# working with office tools
I am planning to generate 8 to 15 reports in sql server report server 2008. I want to create the 8 to 15 separate sql server reports and tie them together with a table of contents in a c#.net 2008. I then want to export these reports into an electronic format to email to users. Can you give me suggestions on how to accomplish this task? On 20/03/2010 18:15, Wendy Elizabeth wrote: > I am planning to generate 8 to 15 reports in sql server report server 2008. > I want to create the 8 to 15 separate sql server reports and tie them > together with a table of contents i...

Outlook 2002 vs. 2003 Cached Mode
We have Exchange 2000 and are running some of our Outlook 2003 clients in Cached Mode. Is there a way to run Cached Mode in Outlook 2002? Nope. This is only available in Outlook 2003. -- Patricia Cardoza Outlook MVP www.cardozasolutions.com Author, Special Edition Using Microsoft Outlook 2003 ***Please post all replies to the newsgroups*** "Jennifer Auguston" <jeno@lynden.com> wrote in message news:035001c3c017$d53e0c20$a101280a@phx.gbl... > We have Exchange 2000 and are running some of our Outlook > 2003 clients in Cached Mode. Is there a way to run Cached > ...

Combo Box Not Working
I’m new to access but learning quickly. I’m trying to create a data base for our “time change” items on out plant equipment. Such as; Furnace (asset) Clutch (part) Installed date (date installed) Replacement date (set date in the future e.g. 6 months from install date) I already have a table with the columns named asset, part, installed date and replacement date. It’s called Table 1. All dates are formatted to medium date format and input mask the same. I also have a table with IntervalTitle, Interval and IntervalIncrement set as follows: IntervalTitle Inte...

Access shortcust not working after updates
Hi, After windows update installed IE7 our shortcuts to Access databases quit working. We need to open access the browse to the db file and open it. Why did shortcuts quit working? Thanks If the shortcut points to a share on a server, you might need to adjust the IE7 security settings. These are the settings that worked for a similar setup at a client. Open the IE settings from Tools, Internet Options. On the Security tab select Local Internet and click Sites. Clear the checkbox for "Automatically detect intranet" and check the other 3 boxes. Click the Advanced button on th...

The system works! (Outlook 2003 result)
Hi, A friends PC has been having trouble with Outlook 2003. It was crashing on mail-send and not auto-suggesting addresses. Detect and Repair didn't fix it, neither did a complete reinstall. A trawl of this newsgroups archives suggested that a new profile might be the way to go, so I tried this. Worked a treat. She's now happy that Outllook works,so I'd thought I'd just say a huge "THANKS!" to the resident gurus. Sometimes, the system works the way it ought to. So, to all the folks who have a macro for "This is not an Outlook Express newsgroup" and t...

Auto Save Add-In
Dear "Guest" I can not understand your complaint, I think you need to read th thread from beginning to end. Dave suggested a macro to resolve my problem of Auto Save not retainin its settings; and I asked him for more details on how to enter th macro. As far as I am concerned it is all relevant to the query and you hav no need to slag us off. PS Be brave and Log I -- Charles ----------------------------------------------------------------------- CharlesF's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=874 View this thread: http://www.excelforum.com...

REmote Display not working using win ce6.0
Hi am vinoth am right now trying to connect the remote display in my pc. i am using omapL138 EVM kit with win ce6.0. i can able to do all the things only i cant able to see my device when i run cerdisp or cerhost. i cant unable to solve or find the problem. am using kitl as transport and server.i can able to attach the device.i can get the bin image. Thanks Vinoth. -- vinoth Message posted via PocketPCJunkies.com http://www.pocketpcjunkies.com/Uwe/Forums.aspx/wince-pb/201005/1 On 5/14/2010 6:54 AM, vinoth006 via PocketPCJunkies.com wrote: > Hi > am vinoth am right...

How do the client cals work?
I'm new to crm and a client of my companies just bout a 6 cal license. My question is, how do I enable the cals? Does it automatically know how many cals i have by the registration key? If I would ever buy more cals, how do I enable them? Hi Zach; The answer depends a bit on the type of licensing model you purchased under, but generally speaking you use the CRM Deployment manager (an app on the CRM server) and you will see a node there called License. You should be able either add your key there, or update the license key information there. Dave Ireland "Zach Thomas"...

Ctrl+Alt+L does not work.
Hi All: In VS 2008, the accelerator of active resolution bar is Ctrl+Alt+L. But it does not work. I create a MFC mdi sample, and set a menu's accelerator to Ctrl+Alt+L, it does not work too. Why? Thanks Fiveight Are you sure it's just that keystroke combination that doesn't work? The first thing I would do is set it to something else (like Alt+F2) and see if that works just to make sure it's not something in the focus mechanism. If that does work, then my guess is that you may have something else with the same keystroke elsewhere that has prior focus. For examp...

decimal fraction in actual work on resource usage view
Hello, we are not using timesheet yet but we enter actual values manually in resource usage view. But we can see work in decimal fractions (like 4,25 hrs) but we can not enter decimal fractions in actual work fields. When we try to put 4,25 in there, it sets to 4 and change the task duration (whihc is expected) How can we enter decimal fractions in there? Please help.. regards Hello cemipalooza, I'm able to enter Actual Work decimals in the Resource Usage as well in the Task Usage (both in 2003 and 2007 versions) Have you tried to enter "minutes of work" : for e...

Working with many worksheet and pick up data!
I have a excel workbook with many simular formated sheet but different data. And like to pick the value in cell A1 from ten sheets. Then I like to visualize them in one sheet as a vector or matrix of data (two dimentional data) for to easely work with them`? I know we do summarize them like SUM(sheet1:sheet10!A1) but like to use the data as they are. "spread them out as a vector" and make arrays of them if nessecarly.... Should be a lot of possibilities and power here anyone who can help on the track here, then I would have been very greatful? Wiggo Not quite understanding what f...

Code to Dynamically Filter a Report; Not Working
I’m struggling a bit with some code that dynamically filters elements in a report. I have a form with the following objects: lstCustomer, lstExecBroker, an Option Group named ‘fraTrader’, with three radio buttons; optOption, optCross, optBoth. Also, I have cboSortOrder1, cboSortOrder2, and cboSortOrder3 as well as cboSortOrder1, cboSortOrder2, and cboSortOrder3, all of which control sort order. Finally, here’s the code: Private Sub cmdApplyFilter_Click() Dim varItem As Variant Dim strCustomer As String Dim strExecBroker As String Dim strTrade As String ...

detailed inventory does not work with non bar code tapes.
I would like to verify that the scheduled inventory still does NOT work with non barcoded tapes. We have a HP 1/8 tape inventory using 8 non bar coded tapes. The scheduled inventory runs every day for about 1 second and does NOT reveal what the tapes are. A manual detailed inventory does work. I wonder why MS would program it this way? Tim This is an issue which we have fixed in DPM 2010. The problem was that the scheduled inventory was not doing detailed inventory on newly added media. Can you install DPM 2010 Beta from https://connect.microsoft.com/Downloads/Downloa...

Customize Outlook Today is not working #2
Hi, I have customized my outlook today to show some folder in my PST file. After that I have renamed the folders, Now I am unable to see the renamed folders and also when I click on "Customize Outlook Today...", I am not getting the customization page. I wondering what might be the cause for such an error. Please let me know what could be the cause. Thanks in advance. Regards, Vidya Sagar Choudhary, Bellamkonda Vidya Sagar Choudhary Bellamkonda <vidyasagar@bellamkonda.com> wrote: > I have customized my outlook today to show some folder in > my PST file. After t...

Reflection not working anymore if creating the child window in a separated thread
Hi folks, I have a weird behaviour when creating a child window (CTreeCtrl derivated class) in a separated thread (to handle asynchronous operations more gently) : message reflection is not working anymore. The Win32 Documentation seems OK for creating child windows in a thread other than the main thread (ie. the parent), and after overriding Create() (the new Create() function starts a thread, create the window, and enter in the second message pump), everything works fine. Except that notification messages (reflection) seems never fired - especially TVN_* notifications, which are not...

OnInitDialog to populate ComboBox wont work due to missing hwnd ?!
I always thought that OnInitDialog will be called *after* the dialog- elements were created, but in this function, calling create leads to OnInitDialog without setting HWNDs correctly. pTab->pPage->ShowWindow(SW_SHOW) sets up all correctly for the first time, so OnInitDialog should be called *after*, shouldnt it?. What do i mess up? i do the following in a class derived from CTabCtrl: void CQTabCtrl::PageLoad(int nIndex) { RECT rc; GetClientRect(&rc); AdjustRect(false, &rc); //pTab is a struct with a pointer to a CWnd //derived class and some other data... SQTabTab* pTa...

Why isn't autocorrect working on two initial capital letters?
I have my autocorrect settings set to change two initial caps to only capitalize the first letter. But the word "STrymon" (the name of a river in Macedonia) doesn't get changed to "Strymon." I looked in my autocorrect exceptions and there was nothing about allowing this word to remain uncorrected (the only entry I have in the exceptions for initial caps is the term "IDs"). Is there any reason why this isn't being changed---and what do I have to do to get Word 2002 to change these initial two capital letters? Never mind. I just changed it myself, a...

Can't confirm Windows Update is working
Not sure how to do this, but here goes. Have a student running XP SP3 who wants to know that she's up to date with her updates. Windows settings say automatic updates are on. When she tries to run the manual update it fails. Windows suggests settings, which we set, but to no avail. Downloaded latest WU utility, still nothing. Tried the NJR fix, nothing. Just downloaded the REGISTERY.BAT file I found here, and will try it and post results here. Please let me know what additional information you need and what I need to do to allow her to simply click on the Windows Update and s...

GP Timesheet V7.50.48 should work with Firefox
This product is a piece of ^&*( that doesn't work properly with Firefox. Hidden menu items ensure that it is unusable. Even with IE, the behaviour of the app is flaky and a clear sign that Microsoft knows nothing about coding in Java. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agre...

2005 didn't crash, 2006 and 2007 do
My system is up to date with Microsoft Update EXCEPT I am using IE6 (not IE7). I've also just uninstalled CitiVAN because I read some reports in this newsgroup about problems with Money and CitiVAN. It's XPSP2. Right now, I've uninstalled 2007 and installed 2006. It will crash even in safe mode if I select File.Repair. When I run safe mode with networking or boot normally, even if I request to work offline, it will crash about 30-60 seconds after starting, even if I do nothing. One second I'm looking at the "My Money" home page, and the next, it's gone...

Working with multiple files/workbooks cross linked
Hi, It seems that the dozen workbooks I have created and the cross sharing of nformation with some single filesworkbook sharing several other files / workbooks need to have the files all open otherwise the paths seems to get a bit mixed up. Is there a way then that will open all files related to a group when I want to work on a particular set of files but as mentioned get ALL the oher files/ workbooks open to ensure the links all work corretly? Thanks Mike Here is an example with three workbooks: first.xls second.xls third.xls Let's say that if one of the files is opened, we wa...