Solved

About the  L"" convertation

Posted on 2001-06-26
9
320 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

948 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now