473,378 Members | 1,209 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

convert char * (argv[]) to wstring and to LPCWSTR

I have been looking all over the place for a method to take command line
arguments and convert them to a string or wstring so i can process the data
and then covert the resulting strings to LPCWSTRs. I have tryed several
methods and none work. They include:
the convert utilities A2W but that does not compile because of unknow
variables declared in the convert header file.
MultiByteToWideChar which seems to work once but not the second time i go to
use it.
The problem with all the task scheduler examples is they only show how to
work with literal (hardcoded) values for CPCWSTRs. and i can not find any
examples of how to just convert command line arguments to LPCWSTRs.

Thanks in advance,
Fred

Feb 28 '06 #1
9 9290
one additional requirement is that what ever i do works in the non-.NET
environment, meaning the old NT environment.

"ka1cqd" wrote:
I have been looking all over the place for a method to take command line
arguments and convert them to a string or wstring so i can process the data
and then covert the resulting strings to LPCWSTRs. I have tryed several
methods and none work. They include:
the convert utilities A2W but that does not compile because of unknow
variables declared in the convert header file.
MultiByteToWideChar which seems to work once but not the second time i go to
use it.
The problem with all the task scheduler examples is they only show how to
work with literal (hardcoded) values for CPCWSTRs. and i can not find any
examples of how to just convert command line arguments to LPCWSTRs.

Thanks in advance,
Fred

Feb 28 '06 #2
ka1cqd wrote:
I have been looking all over the place for a method to take command line
arguments and convert them to a string or wstring so i can process the data
and then covert the resulting strings to LPCWSTRs. I have tryed several
methods and none work. They include:
the convert utilities A2W but that does not compile because of unknow
variables declared in the convert header file.
MultiByteToWideChar which seems to work once but not the second time i go to
use it.
The problem with all the task scheduler examples is they only show how to
work with literal (hardcoded) values for CPCWSTRs. and i can not find any
examples of how to just convert command line arguments to LPCWSTRs.

Thanks in advance,
Fred


Fred:

A2W is part of MFC/ATL so if it does not work it is because you are not
using it correctly. Did you read the documentation?

Likewise for MultiByteToWideChar().

Which version of VC++ are you using?

David Wilkinson
Feb 28 '06 #3
I have read all the info about both methods that i could find on MSDN and
used the code examples for there and could not get them to work.

I have since found, mbstowcs() which appears to work. also it appears to
backward compatible.

Where do i find the doucmentation on how to use the MFC/ATL??

How do you tell what version of the complier is being used? When i start
it, it just says visual studio .net and if i look at the versions under help
about i see a number
69586-335-0000007-18820.

"David Wilkinson" wrote:
ka1cqd wrote:
I have been looking all over the place for a method to take command line
arguments and convert them to a string or wstring so i can process the data
and then covert the resulting strings to LPCWSTRs. I have tryed several
methods and none work. They include:
the convert utilities A2W but that does not compile because of unknow
variables declared in the convert header file.
MultiByteToWideChar which seems to work once but not the second time i go to
use it.
The problem with all the task scheduler examples is they only show how to
work with literal (hardcoded) values for CPCWSTRs. and i can not find any
examples of how to just convert command line arguments to LPCWSTRs.

Thanks in advance,
Fred


Fred:

A2W is part of MFC/ATL so if it does not work it is because you are not
using it correctly. Did you read the documentation?

Likewise for MultiByteToWideChar().

Which version of VC++ are you using?

David Wilkinson

Feb 28 '06 #4
Hi ka1cqd!
I have been looking all over the place for a method to take command line
arguments and convert them to a string or wstring so i can process the data
and then covert the resulting strings to LPCWSTRs. I have tryed several
methods and none work.
Why not create a unicode-app?
And define the following entry:

int _tmain(int argc, _TCHAR* argv[])

They include:
the convert utilities A2W but that does not compile because of unknow
variables declared in the convert header file.


You shouldn´t use A2W, instead use the new ATL7 macros:
Cx like CA2CW

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Feb 28 '06 #5
ka1cqd wrote:
I have read all the info about both methods that i could find on MSDN and
used the code examples for there and could not get them to work.

I have since found, mbstowcs() which appears to work. also it appears to
backward compatible.

Where do i find the doucmentation on how to use the MFC/ATL??

How do you tell what version of the complier is being used? When i start
it, it just says visual studio .net and if i look at the versions under help
about i see a number
69586-335-0000007-18820.


Fred:

MSDN is the documentation. If you do not tell us what goes wrong, we
cannot help you fix it.

VC5: Visual Studio 97
VC6: Visual studio 6
VC7: Visual Studio 2002.Net
VC7.1: Visual Studio 2003.Net
VC8: Visual Studio 2005

It sounds as if you have VC7 or 7.1. As Jochen mentioned, the ATL
conversion macros were improved as of VC7, though there is a bug (fixed
in VC8) that causes them to fail when converting between UTF-8 to UTF-16
in some languages.

David Wilkinson

Feb 28 '06 #6
Hi Jochen,

if i follow what you suggested, i need to #define _UNICODE and then
everything is in the wide format and i don't have to deal with the
conversion? Is this correct?

Thank you,
Fred

"Jochen Kalmbach [MVP]" wrote:
Hi ka1cqd!
I have been looking all over the place for a method to take command line
arguments and convert them to a string or wstring so i can process the data
and then covert the resulting strings to LPCWSTRs. I have tryed several
methods and none work.


Why not create a unicode-app?
And define the following entry:

int _tmain(int argc, _TCHAR* argv[])

They include:
the convert utilities A2W but that does not compile because of unknow
variables declared in the convert header file.


You shouldn´t use A2W, instead use the new ATL7 macros:
Cx like CA2CW

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Feb 28 '06 #7
Hi ka1cqd!
if i follow what you suggested, i need to #define _UNICODE and then
everything is in the wide format and i don't have to deal with the
conversion? Is this correct?


Yes. By the way: This is the default setting for all new projects in VC2005.

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Feb 28 '06 #8
> if i follow what you suggested, i need to #define _UNICODE and then
everything is in the wide format and i don't have to deal with the
conversion? Is this correct?

Because you use Visual Studio .NET, you can just select "Use Unicode
Character Set" from Project Properties -> General -> Character Set.
It will define both _UNICODE and UNICODE (for the CRT and Win API
respectively).
--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Mar 1 '06 #9
"ka1cqd" <ka****@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
I have been looking all over the place for a method to take command line
arguments and convert them to a string or wstring so i can process the
data
and then covert the resulting strings to LPCWSTRs. I have tryed several
methods and none work. They include:
the convert utilities A2W but that does not compile because of unknow
variables declared in the convert header file.
MultiByteToWideChar which seems to work once but not the second time i go
to
use it.
The problem with all the task scheduler examples is they only show how to
work with literal (hardcoded) values for CPCWSTRs. and i can not find any
examples of how to just convert command line arguments to LPCWSTRs.


If you want to keep your application ANSI, you can use GetCommandLineW() and
CommandLineToArgvW().

Regards,
Will
Mar 3 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate...
3
by: Michael Breidenstein | last post by:
Hi, anybody can help me to convert a "char *" to LPCWSTR with the following function: LPCWSTR charP2LPCWSTR(char *szText){ LPCWSTR tmp; tmp=szText; // At this point I need help
6
by: jalkadir | last post by:
How can I conver a char to std::wstring, for intance time_t Time_t; std::wstring Date; time( &Time_t ); Date = ctime( &Time_t ); or strd::string wstr; str = __FILE__;
8
by: ppcdev | last post by:
Here's what I try : LPCTSTR tst = (LPCTSTR) (LPCWSTR) Marshal::StringToHGlobalUni(str); c:\MyNetPrj\Prj0001\stunt.cpp(244): error C2440: 'type cast' : cannot convert from 'System::IntPtr' to...
3
by: Maileen | last post by:
Hi, How can we convert string^ to String or to LPCWSTR ? thx, Maileen
6
by: gerg | last post by:
How would one convert a wstring to a string? This is what I have so far: bool copyto(std::string& l,std::wstring& r) { bool ret = false; size_t i = 0; const size_t n = r.length()+1;
7
by: nicolas.hilaire | last post by:
hi all, i'm using this code to convert a String ^ in char * String ^str = "string .net"; IntPtr p = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str); LPCSTR str2 =...
1
by: asenthil | last post by:
Hai this is senthil... I had tried to write a string which fetched from a database. into a file... when i tried to compile the solution the following error occurs like this error C2664:...
4
by: =?ISO-8859-2?Q?Boris_Du=B9ek?= | last post by:
Hi, I have an API that returns UTF-8 encoded strings. I have a utf8 codevt facet available to do the conversion from UTF-8 to wchar_t encoding defined by the platform. I have no trouble...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.