const char* TO BOOL LPCTSTR

Started by
4 comments, last by janta 16 years, 7 months ago
i need the method below to read a file,in generally,lpszPathName give the name or the path of the file,but how to convert this in const char*? BOOL COpenGLFrameDoc::OnOpenDocument(LPCTSTR lpszPathName) { if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE; return true; }
Advertisement
LPCTSTR is a const char* (no conversion required) or a const wchar_t* (mbstowcs_s) depending on whether you're using unicode or not.
LPCTSTR is short (or cryptic) for Long Pointer Constant T-String. A T-string is an array of TCHAR which in turn is "char" or "wchar_t" depending on whether unicode is enabled or not in your project as ToohrVyk pointed out.

There is also LPTSTR (long pointer to non-constant T-string) LPSTR (ansi string), LPCSTR (constant ansi string), LPWSTR (wide-char, or wchar_t, string) and LPCWSTR (constant wide-char string).
Yeah,can you give me an example to illustrat this.

i have a class and its method is READFILE(const char* path),and i need the lpszPathName must be convert in char*,so how to do this?
please in example
BOOL COpenGLFrameDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;

//conver it into const char*
//
//const char* path = ?????

myclass.READFILE(path);
return true;
}
If you're on Windows, have a look at the WideCharToMultiByte function.
Assuming you're not using unicode character arrays, lpszPathName ___IS___ of type "const char *"

BOOL COpenGLFrameDoc::OnOpenDocument(LPCTSTR lpszPathName){	if (!CDocument::OnOpenDocument(lpszPathName))		return FALSE;        myclass.READFILE(lpszPathName);	return true;}


Now please, some people made the effort to reply, so make the effort to understand what they replied instead of waiting to be fed with some code to copy and paste into your application. Everything you needed to fix your issue was ToohrVyk's reply, #1 right after your post.

/me just wasted 5 minutes of his life.

This topic is closed to new replies.

Advertisement