Solved

About the  L"" convertation

Posted on 2001-06-26
9
325 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
[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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

631 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