473,545 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 wWinMainCRTStar tup as the Entry Point in the linker properties.

Thanks in advance,
Craig

Oct 16 '07 #1
5 1972

"Craig Johnston" <Cr***********@ discussions.mic rosoft.comha scritto nel
messaggio news:DF******** *************** ***********@mic rosoft.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(bu ffer, retval, &charsout);
}
} else {
WRITE_STRING(te xt.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\sr c\output.c
This code is in the function dll!_output shown in the call stack below:

msvcr71d.dll!wr ite_string(char * string=0x7c9131 dc, int len=0x7c913212,
_iobuf * f=0x00000000, int * pnumwritten=0x7 c913288) Line 1258 + 0x19
msvcr71d.dll!_o utput(_iobuf * stream=0xcccccc cc, const char *
format=0xcccccc cc, char * argptr=0xcccccc cc) Line 1031 + 0x18 Ccccccccc()
Visual Engineer.exe!$E 7() Line 2602 + 0x28 C++
msvcr71d.dll!_i nitterm(void (void)* * pfbegin=0x00b2f 4b8, void (void)* *
pfend=0x00b354d 4) Line 600
Visual Engineer.exe!wW inMainCRTStartu p() Line 336 + 0xf
kernel32.dll!7c 816fd7()

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\sr c\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
3738
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 (the first was required for Python 2.3.3 on RedHat 9): ../configure --prefix=/net/python --enable-unicode=ucs4 ../configure --prefix=/net/python...
8
3644
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 representation, some systems add at the beginning of the file a BOM mark (Windows?), some don't. (Linux?). Therefore, the exact same text encoded in the same...
2
1809
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
7521
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 comes back contains garbage characters for Chinese, Russian etc languages. The english characters come back fine using ADO. It seems that DB2...
1
2371
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 others to define a certain font (MS Arial Unicode) for the user controls, and provide custom controls which have the font property fixed set to this...
12
3852
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, some Chinese characters are illegible( I see sizeof(TCHAR)=2 being displayed). Your idea is welcome. case WM_PAINT: hdc = BeginPaint(hWnd, &ps);
5
2525
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 now I need it to work on Russian computers and I realized that the application should be converted to Unicode to work in Russian. I am totally new...
0
6583
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 every the of C++ project I try to build. Not just Class Libraries, but a plain Windows Form Application as well. I've tried creating new...
5
1736
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 Authenticode signature to project output. The second line is harder to translate. The reason is that the second line says it successfully signed...
0
7680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7778
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6003
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3476
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.