Solved

About the  L"" convertation

Posted on 2001-06-26
9
322 Views
Last Modified: 2010-04-02
Please help me.
I need to use a string variable instead of the L"" macro.
How can i do that?


Regards
Andla
0
Comment
Question by:andla
9 Comments
 
LVL 7

Expert Comment

by:KangaRoo
ID: 6228837
Could you elaborate? What is this 'L' macro? Could you paste its #define?
0
 
LVL 6

Expert Comment

by:snoegler
ID: 6228851
L"" is no macro but a prefix for unicode strings.

>> I need to use a string variable instead of the L"" macro.
You mean wchar_t[] strings?
0
 
LVL 1

Author Comment

by:andla
ID: 6228871
Hello KangaRoo and Snoegler nice to se you. :-)

How can i do this?

char test[]="Hello World";

wchar_t litt; //?????
litt=L(test) //?


/Andla
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:andla
ID: 6228881
The real code looks like this so you know what i'm trying to do. Not sure how strict this is. Pretty new to ADO.



ADODB::_ConnectionPtr  Con;
Con.CreateInstance(__uuidof(ADODB::Connection));//Create COM object.
char stropen[300];
wsprintf(stropen,"DSN=%s",strdatabase);//Remember that strdatabase was from the TreeView_GetItem(m_view,&tvi);
Con->Open(stropen, L"", L"", -1L);

/Andla
0
 
LVL 32

Expert Comment

by:jhance
ID: 6228932
The L macro forces a string to be UNICODE when UNICODE is not the default for the application.  For your wsprintf function, the strings must be UNICODE and you need to force them in an ASCII application to be UNICODE.  That's what the L does.

So:

WCHAR *wszString = L"This is a test";

makes a UNICODE string.
0
 
LVL 6

Expert Comment

by:zebada
ID: 6230616
There's a previous discussion on using L in macros to convert strings to wide strings at:
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cprog&qid=20045026
Not sure how relevant it is...
0
 
LVL 1

Author Comment

by:andla
ID: 6234885
It seams that the L macro doesn't work for normal strings (char* or char[]). Is there a simpel converting function for this ?

I need to convert a normal string variable (not defined) to a unicode string.

/Andla
0
 
LVL 32

Accepted Solution

by:
jhance earned 20 total points
ID: 6234994
The "L" macro is NOT a type conversion utility.  It works only at COMPILE time to produce a UNICODE string constant.

If you need to convert from ASCII to UNICODE or back there are several alternatives.  If you are using MFC, there are several macros defined in afxpriv.h that are convenient.  In particular they are A2W or W2A.

Also at your disposal are the Windows SDK functions:

MultiByteToWideChar()
WideCharToMultiByte()

functions.  These are the "standard" means of converting.

0
 
LVL 1

Author Comment

by:andla
ID: 6245299
MultiByteToWideChar()
WideCharToMultiByte()

Thanks jhance!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

830 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