[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 759
  • Last Modified:

problems with convertion LPCTSTR and char

I get problems when trying to send char* cHTML to the WriteToFile method.
char szBuffer[1024];
char* cHTML;


cHTML = (char*)szBuffer;
WriteToFile("C:\\rInfo.txt",(LPCTSTR) cHTML); //error C2664: 'WriteToFile' : cannot convert parameter 1 from 'const char [13]' to 'LPCTSTR'

/////////////////////////////////
// WRITE TO A FILE
/////////////////////////////////
void WriteToFile (LPCTSTR lpFileName, LPCTSTR msg)
{

     fstream f;

     f.open(lpFileName, ios::app);

     //Save the message
     f << msg << endl;

     f.close();

}

Any idea?

0
m-jansen
Asked:
m-jansen
  • 3
  • 2
1 Solution
 
jkrCommented:
Make that

cHTML = (char*)szBuffer;
LPCTSTR pszFile = "C:\\rInfo.txt";
WriteToFile(pszFile,(LPCTSTR) cHTML);

and that should work.
0
 
m-jansenAuthor Commented:
This is what that happen now

 cHTML = (char*)szBuffer;
 LPCTSTR pszFile = "C:\\rInfo.txt";  // Error      3 error C2440: 'initializing' : cannot convert from 'const char [13]' to 'LPCTSTR'
 WriteToFile(pszFile,(LPCTSTR) cHTML);
0
 
jkrCommented:
That's odd - are you compiling with UNICODE defined? If so, try

#include <tchar.h>

LPCTSTR pszFile = _T("C:\\rInfo.txt");
WriteToFile(pszFile,(LPCTSTR) cHTML);
0
 
m-jansenAuthor Commented:
> That's odd - are you compiling with UNICODE defined?
It looks like that - Configuration Properties -> Characer Set -> Use Unicode Character Set (default in VC8-2005)
0
 
m-jansenAuthor Commented:
it compiles too. thanks alot.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now