Solved

About the  L"" convertation

Posted on 2001-06-26
9
319 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

746 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

11 Experts available now in Live!

Get 1:1 Help Now