By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,411 Members | 999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,411 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
> 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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.