473,461 Members | 1,109 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

TEXT( ) function

Hello,

I am something of a windows API newbe and would apreciate any help
that you might be able to provide.

I am attempting to understand exactly what the TEXT() function does.
I have seen that it is defined as an unsigned short pointer...
presumably converting a text string into a wide char. Unfortunatly,
when i attempt to convert a string to a wide char the string gets
garbled and is unusable. Can anyone find a problem in the following
code segment? (The printf does not display 'x had a value of Today is
your lucky day!' for y.

Many thanks,

Michael Benson

int function(void)
{
char x[100];
TCHAR y[100];

sprintf(x,"Today is your lucky Day!");
_stprintf(y,TEXT("x had a value of %s\n"),x);
printf("X = %s\nY = %s\n\n",x,y);
return 0;
}
Jul 22 '05 #1
2 3660
Michael Benson wrote:
I am something of a windows API newbe and would apreciate any help
that you might be able to provide.

I am attempting to understand exactly what the TEXT() function does.
[...]


You're in a wrong newsgroup. You need comp.os.ms-windows.programmer
Jul 22 '05 #2
Michael Benson wrote:
I am something of a windows API newbe and would apreciate any help
that you might be able to provide.
TEXT() is on-topic on newsgroups that cover the Windows API. This newsgroup
is only qualified to answer platform-neutral questions.

TEXT("x") wraps either "x" or L"x", depending whether one of UNICODE or
_UNICODE are defined. No idea which; just enable them both.

Modern GUI code should use Unicode instead of a codepage, so its strings
should be L. TEXT() is a hack used to allow a program to compile with either
default 8 or 16 bit strings, and leads to a few abuses. Only use it when you
mean it.
I am attempting to understand exactly what the TEXT() function does.
I have seen that it is defined as an unsigned short pointer...
presumably converting a text string into a wide char. Unfortunatly,
when i attempt to convert a string to a wide char the string gets
garbled and is unusable. Can anyone find a problem in the following
code segment? (The printf does not display 'x had a value of Today is
your lucky day!' for y.

Many thanks,

Michael Benson

int function(void)
{
char x[100];
TCHAR y[100];

sprintf(x,"Today is your lucky Day!");
_stprintf(y,TEXT("x had a value of %s\n"),x);
With TEXT() set to produce 8-bit string literals, that will accidentally
work.

With TEXT() set to produce 16-bit string literals, the 't' in _stprintf()
will see L"x had a value of %s\n" correctly, but it will not magically
promote the 8-bit array x to a 16-bit array x.

What you are researching here is not character widths so much as typesafety.
The printf family of functions are not typesafe, because a compiler cannot
use means within the C++ language itself to match an expression code, %s, to
an argument of the correct type.

The fix:

TCHAR x[100];

Further questions about typesafety are on-topic here, and questions about
MS's usual level of it are on-topic on an MSDN newsgroup.
printf("X = %s\nY = %s\n\n",x,y);
return 0;
}


--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #3

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

Similar topics

6
by: Max | last post by:
i want to insert a predefined string in a textarea when i right click on the mouse. i need to do it in internet explorer and mozilla.
4
by: Dru | last post by:
Hi, I am making a textarea for people to add/modify their text for descriptions products. I want to have buttons (or just text links) with functions that will allow them to bold, italicize, sup,...
2
by: Rolan | last post by:
Need some assistance with regard to the following basic Function to change digits to text, i.e., 295.78 = RTELG. Any suggestions or ideas will be appreciated. Thanks. Function dtt(Cost As...
2
by: jmarendo | last post by:
Hello, After reading through the "Table Basics - DOM - Refer to table cells" example at mredkj.com , I modified the code for my own purposes. In the modified version, I create a hyperlink and...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
1
by: destiny007 | last post by:
can any one help me to write code to capture selected text from a page but problem is that i am not able to decide where to call the functio.in this case the function is called in all cases of mouse...
4
ddtpmyra
by: ddtpmyra | last post by:
Im try to catch the part numbers on a specifict field inside access query and I dont know what kind of function to use. example data: new order #ABC-001 the result i wanted is to get all...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...
0
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...
0
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 ...

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.