Solved

How do I write the Windows TEXT macro on linux?

Posted on 2010-11-27
5
839 Views
Last Modified: 2012-05-10
I am in the process of converting some c++ code from Windows to C++. I have a bunch of TEXT macros. TEXT("MyString") which makes L"MyString" or "MyString depending on some condition.

Ideally, on linux, I would simply like to define a macro that does the above. Something like:

#ifdef USE_WIDE_CHAR
#  define TEXT(x) L#x
#else
# define TEXT(x) x
#endif

But, the above does not seem to compile. Anyone know how to do this?

Thanks!
0
Comment
Question by:rjsurati
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 34222369
The same should work un Linux - see http://kfsone.wordpress.com/2008/08/26/unicode-literals-and-gcc/ ("Unicode literals and GCC"). What errors are you getting?
0
 
LVL 9

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 34222733
If you want to use wide char, then define USE_WIDE_CHAR.
The file inwhich you need it, just define.better if defining inside a common file( which you need more frequently)

#define USE_WIDE_CHAR

Not worked on linux, but hope unicode and ascii concept is same irrespective of platform.
0
 
LVL 9

Expert Comment

by:masheik
ID: 34224055
You were not showing us the errors.I dont know how your project files were organized.    Say your project has 5 source files and 6 header files and I assume you were including one common header included to all other header files or to all the source files or to where it was required to make all the the declaration available to the source files , then in that header file use  #define USE_WIDE_CHAR                           and conditional includes  
0
 
LVL 11

Accepted Solution

by:
DeepuAbrahamK earned 500 total points
ID: 34228398
For ASCII, a LPTSTR is a char*.
For Unicode it becomes a wchar_t*.
Try these:
#ifdef USE_WIDE_CHAR
#define TEXT(x) L ##x
#else
#define TEXT(x) x

0
 

Author Comment

by:rjsurati
ID: 34294977
Sorry guys, this one ended up being my fault. I had

#define TEXT(x) L #x
does not work

#define TEXT(x) L ##x
does.

In my code, I accidentally added a ';' which is why I was so confused.

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTTPSendRequest with WinINet delays on first call 11 119
print bytes of an integer 6 48
VPN, Squid-  unable to log https requests 5 110
ossec: how to extend rules 1002 and 1003 2 44
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question