472,328 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 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 1878

"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...
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...
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++)...
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...
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...
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...
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...
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...
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...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.