Solved

About the  L"" convertation

Posted on 2001-06-26
9
323 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
Technology Partners: 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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c++ substatte a varabe for a string in a LPCTSTR statment 8 100
sorting efficency of sorting algorithm 30 147
How do i run a c++ file? 15 57
Need some help with mailto 16 41
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

738 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