I'm not exactly sure which API's are supported but I use these when programming Windows CE devices:
MultibyteToWideChar -> CHAR (1 byte) to WCHAR (2 byte)
WidecharToMultibyte -> WCHAR (2 byte) to CHAR (1 byte)
BUT>>>
LPCTSTR is type defined as a TCHAR and CreateFile takes a TCHAR as a parameter so that all looks good.
It looks to me like UNICODE isn't defined.
Try:
#define UNICODE
Also using L in front of a string will always be multibyte string. Using TEXT or _T depends on whether UNICODE is defined or not.
Ex. If unicode IS NOT defined
L"String" = Wide character string
TEXT"String" = Multibyte character string
MSDN is a programmers best friend:
http://msdn.MS.comThis is from the winnt.h header file:
//
// Neutral ANSI/UNICODE types and macros
//
#ifdef UNICODE // r_winnt
#ifndef _TCHAR_DEFINED
typedef WCHAR TCHAR, *PTCHAR;
typedef WCHAR TBYTE, *PTBYTE;
typedef wchar_t _TCHAR;
typedef wchar_t _TSCHAR;
typedef wchar_t _TUCHAR;
typedef wchar_t _TXCHAR;
typedef wint_t _TINT;
#define _TCHAR_DEFINED
#endif /* !_TCHAR_DEFINED */
typedef LPWSTR LPTCH, PTCH;
typedef LPWSTR PTSTR, LPTSTR;
typedef LPCWSTR PCTSTR, LPCTSTR;
typedef LPWSTR LP;
#define __TEXT(quote) L##quote // r_winnt
#else /* UNICODE */ // r_winnt
#ifndef _TCHAR_DEFINED
typedef char TCHAR, *PTCHAR;
typedef unsigned char TBYTE , *PTBYTE ;
#define _TCHAR_DEFINED
#endif /* !_TCHAR_DEFINED */
typedef LPSTR LPTCH, PTCH;
typedef LPSTR PTSTR, LPTSTR;
typedef LPCSTR PCTSTR, LPCTSTR;
#define __TEXT(quote) quote // r_winnt
#endif /* UNICODE */ // r_winnt
SAMPLE CODE:
//
//Calling this way gives the number of bytes needed to store the converted string
//likewise for WidecharToMultibyte
INT nBytes = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pSingleByteString, -1, NULL, NULL );
//
//Allocate space to store the wide character string
PWCHAR pWideString = (PWSTR)malloc( sizeof(WCHAR)*( nBytes + 1 ) );
//
//Use memset here or NULL terminate the string after conversion
memset( pWideString, 0, nBytes + 1 );
//
//Convert the single byte string to wide character
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pSingleByteString, strlen(pSingleByteString), pWideString, nBytes + 1 );
Hope that helps.....
This post has been edited by xxxfubar187xxx: Jun 22 2004, 08:26 PM