From: Rayne on
Hi all,

I'm using Visual Studio .NET 2003, and I'm trying to write a program
that can compile in both Unicode and Multi-Byte. Hence, the use of
TCHAR. However, I'm getting errors on pcap functions and socket
functions:

error C2664: 'pcap_findalldevs': cannot convert parameter 2 from
'TCHAR[256]' to 'char *'
error C2664: 'pcap_lookupnet: cannot convert parameter 1 from
'TCHAR[5]' to 'const char *'
error C2664: 'pcap_loop: cannot convert parameter 3 from 'void
(_TUCHAR *, const pcap_pkthdr *, const _TUCHAR *)' to 'pcap_handler'
error C2664: 'pcap_open_live': cannot convert parameter 5 from
'TCHAR[256]' to 'char *'
error C2664: 'pcap_open_offline: cannot convert parameter 1 from
'TCHAR *' to 'const char *'

error C2664: 'recv': cannot convert parameter 2 from 'TCHAR *' to
'char *'
error C2664: 'send': cannot convert parameter 2 from 'TCHAR *' to
'const char *'
error C2664: 'setsockopt': cannot convert parameter 4 from 'const
TCHAR *' to 'const char *'

Please advise.

Thank you.

Regards,
Rayne
From: David Lowndes on
>I'm using Visual Studio .NET 2003, and I'm trying to write a program
>that can compile in both Unicode and Multi-Byte. Hence, the use of
>TCHAR. However, I'm getting errors on pcap functions and socket
>functions:
>
>error C2664: 'pcap_findalldevs': cannot convert parameter 2 from
>'TCHAR[256]' to 'char *'

Presumably because that function doesn't have a Unicode version.

>Please advise.

You can't blindly convert everything in your application to use TCHAR.
If a function only accepts single byte characters, then that's what
you have to give it. If those then need conversion to TCHAR to match
up with other aspects if your application you'll find the A2T and T2A
family of macros useful.

Dave
From: Ulrich Eckhardt on
Rayne wrote:
> I'm using Visual Studio .NET 2003, and I'm trying to write a program
> that can compile in both Unicode and Multi-Byte. Hence, the use of
> TCHAR. However, I'm getting errors on pcap functions and socket
> functions:
>
> error C2664: 'pcap_findalldevs': cannot convert parameter 2 from
> 'TCHAR[256]' to 'char *'

I guess this deals with bytes.

> error C2664: 'recv': cannot convert parameter 2 from 'TCHAR *' to
> 'char *'
> error C2664: 'send': cannot convert parameter 2 from 'TCHAR *' to
> 'const char *'

Same.

You need to convert. Things like USES_CONVERSION/CT2A and similar stuff
help, maybe MultibyteToWideChar/WideCharToMultibyte, if you need to go more
low-level.

TCHAR is _not_ a sane choice for use in a network protocol, in case you were
wondering, rather use UTF-8.

Uli

--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
From: Alex Blekhman on
"Rayne" wrote:
> I'm using Visual Studio .NET 2003, and I'm trying to write a
> program that can compile in both Unicode and Multi-Byte. Hence,
> the use of TCHAR. However, I'm getting errors on pcap functions
> and socket functions:
> [...]

In addition to David's and Ulrich's answers. Many times C
functions treat `char' type as a mere substitution for bytes. So,
quite often when char* parameter is required, then the intention
is to receive/fill a buffer with binary data. In that case you
need to know how to interpret the data instead of converting it
from/to multi-byte and wide characters.

HTH
Alex

From: Giovanni Dicanio on
"David Lowndes" <DavidL(a)example.invalid> ha scritto nel messaggio
news:4kmvm5t9f9dth0fq27vmb27blhu0tqcb85(a)4ax.com...

>>I'm using Visual Studio .NET 2003, and I'm trying to write a program
[...]
> If those then need conversion to TCHAR to match
> up with other aspects if your application you'll find the A2T and T2A
> family of macros useful.

To build on Dave's post, I would suggest the newer CA2T and CT2A from ATL
7+, (instead of the old ATL 3 <X>2<Y> helpers); they have some advantages,
like those explained here:

http://msdn.microsoft.com/en-us/library/87zae4a3(VS.80).aspx

Giovanni