I encountered a compilation error in Visual Studio 2015, that I am trying to convert char
data to LPWSTR
. Can I? Or does it work only with string types?
Here is a piece of my code :
⋮
FILE *sortie;
char fichier[256];// <--- HERE s my char table
int main(int argc, char *argv[])
{
//on masque
HWND hwnd = GetForegroundWindow();
ShowWindow(hwnd, SW_HIDE);
int i, lettre, result, lastresult, lastletter, compteur;
GetCurrentDirectory(256, fichier);
strcat(fichier, "\\fichierlog.txt");
Before posting my question I was at:
I didn't find my case :(
Instead of your current code:
FILE *sortie;
char fichier[256];// <--- HERE s my char table
int main(int argc, char *argv[])
{
//on masque
HWND hwnd = GetForegroundWindow();
ShowWindow(hwnd, SW_HIDE);
int i, lettre, result, lastresult, lastletter, compteur;
GetCurrentDirectory(256, fichier);
strcat(fichier, "\\fichierlog.txt");
do e.g.
auto main() -> int
{
//on masque
HWND hwnd = GetForegroundWindow();
ShowWindow(hwnd, SW_HIDE);
int i, lettre, result, lastresult, lastletter, compteur;
std::wstring fichier( MAX_PATH, L'\0' );// <--- HERE s my char table
const DWORD len = GetCurrentDirectory( fichier.size(), &fichier[0] );
if( len == 0 || len >= fichier.size() ) { throw std::runtime_error( "GetCurrentDirectory failed." ); }
fichier.resize( len );
fichier += L"/fichierlog.txt";
std::ifstream sortie( fichier );
This should fix three issues:
You're compiling as Unicode (probably a Visual Studio project), but the code is for the Windows ANSI API.
You're using a C++ compiler, but the code is low level C.
Too small buffer for maximum path length, and possible buffer overrun for the concatenation.
Note that the ifstream
constructor that accepts a wide string is a Microsoft extension. It will however be practically required for Windows C++ compilers by the file system addition to the standard library in C++17.