Convert Char To TCHAR

S

suddenexpire

For the life of me, I can't figure out what is wrong with this code and
why it is giving me an error.

DWORD size=256;
char CurrentComp[256];
GetComputerName(CurrentComp,&size);

The third line gives an error:
C2664: 'GetComputerNameW' : cannot convert parameter 1 from 'char
[256]' to 'LPWSTR'

Any suggestions on what to do?
 
O

Ondra Holub

(e-mail address removed) napsal:
For the life of me, I can't figure out what is wrong with this code and
why it is giving me an error.

DWORD size=256;
char CurrentComp[256];
GetComputerName(CurrentComp,&size);

The third line gives an error:
C2664: 'GetComputerNameW' : cannot convert parameter 1 from 'char
[256]' to 'LPWSTR'

Any suggestions on what to do?

Array of char is not the same as array of 'some other type'. I guess
from subject, that LPWSTR is probably array of wchar_t. You can not be
simply assign array of char to it.

You can convert it with method widen (basic_iostream<...>::widen)
acording to required locale.
 
J

John Carson

For the life of me, I can't figure out what is wrong with this code
and why it is giving me an error.

DWORD size=256;
char CurrentComp[256];
GetComputerName(CurrentComp,&size);

The third line gives an error:
C2664: 'GetComputerNameW' : cannot convert parameter 1 from 'char
[256]' to 'LPWSTR'

Any suggestions on what to do?

At a guess you are using VC++ 2005. This defaults to unicode (wchar_t). If
you want narrow characters, go to

project properties->configuration properties->general

and select the desired character set.

Questions like this are best asked on

microsoft.public.vc.language
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top