Click to See Complete Forum and Search --> : What's LPCTSTR? and working with strings


THY02K
February 13th, 2001, 07:17 PM
Q1
char MyCharArrayA[30] = "Testing: MyCharArray...";
char* MyCharArrayB[30]; //What is this??
//Note: MyCharArrayA is a char* (character pointer) BUT what's MyCharArrayB? Array of char* pointers?
cout << MyCharArrayB will give u an address.
cout << MyCharArrayB[1] will make yr program crash? Why?

Q2

I cant find the typedef for LPCSTR in msdn. The following is extracted from MSDN. Is LPCSTR an operator of CString class? Or Is it an MACRO? Or is it a SDK defined TYPE (definition in some header file?).

FOR YOUR REFERENCE (from MSDN): Win32 Data Types / check out Platform SDK header files:

(1) The letter T in a type definition designates a generic type that can be compiled for either ANSI or Unicode.
(2) The letter W in a type definition designates a wide-character (Unicode) type.
(3) For the actual implementation of this method, see the WINNT.H header file.

// Generic types

#ifdef UNICODE
typedef wchar_t TCHAR;
#else
typedef unsigned char TCHAR;
#endif

typedef TCHAR * LPTSTR, *LPTCH;

// 8-bit character specific

typedef unsigned char CHAR;
typedef CHAR *LPSTR, *LPCH;

// Unicode specific (wide characters)

typedef unsigned wchar_t WCHAR;
typedef WCHAR *LPWSTR, *LPWCH;

Thanks.

Clearcode
February 14th, 2001, 04:13 AM
LPSTR is a 32-bit long pointer to a C type (null terminated string.

LPCSTR is the same thing, only the string is constant (will not be altered by the called code - what goes in comes out)

LPTSTR indicates that the string can be ANSI or Unicode depending on which entry point in the DLL is used. i.e. if you compile the DLL with the compiler directive #UNICODE, the resulting dll will accept a unicode string, otherwise it will accept an ANSI string.

LPCTSTR is a combination of the above.

HTH,
Duncan

-------------------------------------------------
Got "BigMetalHead"? You will soon
http://www.merrioncomputing.com