views:

367

answers:

2
+1  Q: 

char to LPCTSTR

how to convert char to LPCTSTR in vc++

+1  A: 

if you are using MFC (is your label supposed to be MFC instead of MVC?):

char name[] = "your name";  
CString sName(name);  
LPCTSTR lpszName = sName;  

if you are using Qt, take a look at QString and QByteArray

// (1)
QString filename;
LPCWSTR lpszFilename = filename.utf16(); // alternatively, .unicode()
// alternatively, (2)
QByteArray qBA("abcdef.txt");
QString qString(qBA);
LPCWSTR lpszFileName = qString.utf16(); // or, .unicode() , .utf8()

...
sf.pFrom = lpszFileName;
afriza
you should put your block of code in the question preceded by a newline and prefix them with 4 spaces for every line of codes. click 'edit' somewhere near your question.
afriza
it seems like you are using Qt, please add that to the label.
afriza
I am using MVC. QByteArray qBary; qBary.append(temp); char toChar[512]; for(int ii=0;ii<512;ii++) { toChar[ii]=qBary[ii]; if(qBary[ii]=='\0') { break; } } SHFILEOPSTRUCT sf; memset( sf.hwnd = 0; sf.wFunc = FO_COPY; sf.pFrom = toChar; // error occurring here
A: 

I am using MVC.

QByteArray qBary;
qBary.append(temp);
char toChar[512];
for(int ii=0;ii<512;ii++)
{ 
toChar[ii]=qBary[ii];
 if(qBary[ii]=='\0') 
 { break;
   } } 
 SHFILEOPSTRUCT sf;
 memset(&sf,0,sizeof(sf)); 
 sf.hwnd = 0;
 sf.wFunc = FO_COPY;
 sf.pFrom = toChar; // error occurring here 
what's the error message by the way?
afriza
cannot convert char to LPCTSTR