473,379 Members | 1,220 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,379 software developers and data experts.

Building a Unicode application.

I am in the process of converting an application to Unicode that is built
with Visual C++ .NET 2003. On application startup in debug mode I get an
exception. The problem appears to be that code with #ifndef _UNICDODE is
executed in output.c, the library code for supporting printf functions. I
need to how to get the code that is defined with _UNICODE to be executed
instead. I have defined the _UNICODE constant in the project Properties and
specified wWinMainCRTStartup as the Entry Point in the linker properties.

Thanks in advance,
Craig

Oct 16 '07 #1
5 1955

"Craig Johnston" <Cr***********@discussions.microsoft.comha scritto nel
messaggio news:DF**********************************@microsof t.com...
>I am in the process of converting an application to Unicode that is built
with Visual C++ .NET 2003.
You can go to your project Properties (right click on the project name, and
select "Properties").
Then, in "General" group, go to "Character Set" and choose the option "Use
Unicode Character Set".
instead. I have defined the _UNICODE constant in the project Properties
and
You should define both _UNICODE and UNICODE (however, this is done by the
IDE if you change the configuration as shown above).

If you move to Unicode, you should pay attention in your code, e.g. in
places where you used 'char', you should use TCHAR (than is OK for both ANSI
and Unicode), or wchar_t (for Unicode-only).

Or if you have some string buffers and you have to specify the buffer
length, this length is usually in TCHARs, which is the same of length in
bytes only for ANSI, but *not* for Unicode (for Unicode, you must divide the
total length in bytes by the bytes in a TCHAR, i.e. 2).

So considering the following code:

// Assume DoSomething has a prototype like so:
//
// void DoSomething( LPTSTR bufferPtr, size_t bufferCch );
//
char buffer[200];
DoSomething( buffer, sizeof(buffer) );

If you port to Unicode, you should use:

TCHAR buffer[200];
DoSomething( buffer, sizeof(buffer) / sizeof(buffer[0]) );

(There must be something like _countof() to do the
sizeof(array)/sizeof(array[0]) calculation.)

Giovanni
Oct 16 '07 #2
Craig Johnston wrote:
Mihai and Giovanni
Thanks for responding. I changed the Project properties as you described but
my application is still executing code that has #ifndef _UNICODE wrapped
around it. Do I need to build my own copy of the C run-time library files
with _UNICODE defined?
Craig:

No. Everything should take care of itself.

--
David Wilkinson
Visual C++ MVP
Oct 17 '07 #3
I changed the Project properties as you described but
my application is still executing code that has #ifndef _UNICODE wrapped
around it.
My normal reaction would be "this is not possible"
Unless you have uncovered some really weird bug in the compiler
or the editor/debugger. Which I think it is kind of unlikely, we
are talking about the preprocessor, not some advanced template handling.

Can you "distill" the thing to a small example that you can share?

Do I need to build my own copy of the C run-time library files
with _UNICODE defined?
No, it should not need this.
--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Oct 18 '07 #4
Mihai
This code gets executed on application startup:

#ifndef _UNICODE
if (bufferiswide && (textlen 0)) {
wchar_t *p;
int retval, count;
char buffer[MB_LEN_MAX+1];

p = text.wz;
count = textlen;
while (count--) {
retval = wctomb(buffer, *p++);
if (retval <= 0)
break;
WRITE_STRING(buffer, retval, &charsout);
}
} else {
WRITE_STRING(text.sz, textlen, &charsout);
}
#else /* _UNICODE */

The module that contains this code is in the file C:\Program Files\Microsoft
Visual Studio .NET 2003\Vc7\crt\src\output.c
This code is in the function dll!_output shown in the call stack below:

msvcr71d.dll!write_string(char * string=0x7c9131dc, int len=0x7c913212,
_iobuf * f=0x00000000, int * pnumwritten=0x7c913288) Line 1258 + 0x19
msvcr71d.dll!_output(_iobuf * stream=0xcccccccc, const char *
format=0xcccccccc, char * argptr=0xcccccccc) Line 1031 + 0x18 Ccccccccc()
Visual Engineer.exe!$E7() Line 2602 + 0x28 C++
msvcr71d.dll!_initterm(void (void)* * pfbegin=0x00b2f4b8, void (void)* *
pfend=0x00b354d4) Line 600
Visual Engineer.exe!wWinMainCRTStartup() Line 336 + 0xf
kernel32.dll!7c816fd7()

Thanks,
Craig
"Mihai N." wrote:
I changed the Project properties as you described but
my application is still executing code that has #ifndef _UNICODE wrapped
around it.
My normal reaction would be "this is not possible"
Unless you have uncovered some really weird bug in the compiler
or the editor/debugger. Which I think it is kind of unlikely, we
are talking about the preprocessor, not some advanced template handling.

Can you "distill" the thing to a small example that you can share?

Do I need to build my own copy of the C run-time library files
with _UNICODE defined?
No, it should not need this.
--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Oct 18 '07 #5
The module that contains this code is in the file
C:\Program Files\Microsoft
Visual Studio .NET 2003\Vc7\crt\src\output.c
Ah!

That is part of the CRT.
msvcrXX.dll contains both Unicode and non-Unicode functions.
The file is probably compiled both as Unicode and as non-Unicode and the two
resulting obj files are linked together.

My best guess with this info: you are probably calling a non-Unicode api
from your Unicode application.
Try going step by step and see exactly what call triggers the mess.
That is probably the ansi call.
--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Oct 19 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Russell E. Owen | last post by:
I'm trying to build Python 2.3.4 from source on a RedHat Enterprise machine for installation in a net-wide accessible directory /net/python. I tried all of the following variants of ./configure...
8
by: Francis Girard | last post by:
Hi, For the first time in my programmer life, I have to take care of character encoding. I have a question about the BOM marks. If I understand well, into the UTF-8 unicode binary...
2
by: Grace | last post by:
Dear Sir, By default, an application build on .net framework 1.0 or 1.1 is it a unicode application?? and If i use VS.net 2003 (VC# or VC++) by defualt is it a unicode or ANSI appliation?
1
by: Daman | last post by:
Hi, I am currently facing difficulty displaying chinese, japanese, russian etc. characters. I am using VB 6 and ADO to query the DB2 Version 7.2 unicode database (UTF-8). The resultset that...
1
by: Joerg | last post by:
I am in the process of creating an international GUI application with C# on ..NET1.1 (Win2k), which is supposed to implement a particular look/design. In order to achieve this, I plan amongst...
12
by: Onega | last post by:
Hi I create a simple win32 project (VC2003, windows2003(English) , and do simple paint in WM_PAINT message, when the project use multi-character set, it is OK. but when I change to UNICODE,...
5
by: Sonu | last post by:
Hello everyone and thanks in advance. I have a multilingual application which has been built in MFC VC++ 6.0 (non-Unicode). It support English German Hungarian so far, which has been fine. But...
0
by: Herman Jones | last post by:
I'm getting the following error when I build a Class Library project: Embedding manifest... Project : error PRJ0002 : Error result 1 returned from 'C:\WINDOWS\system32\cmd.exe'. It happens with...
5
by: Norman Diamond | last post by:
Here are two complete lines of output from Visual Studio 2005: 1>$B%W%m%8%'%/%H=PNO$K(B Authenticode $B=pL>$7$F$$$^$9(B... 1>Successfully signed: c:\T The first line means roughly: Doing...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.