Solve the following argument errors


Hello, I can not solve the following argument errors. The code I use is the following:

string pro = "aplicacion";
HRSRC res=FindResource(NULL,pro.c_str(),RT_RCDATA);
HANDLE hFile=CreateFile("C:/Users/Usuario/Desktop/aplicacion.exe",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);


Keep showing error:


mainwindow.cpp: 29: error: conversion from 'const char [6]' to   non-scalar type 'std :: __ cxx11 :: wstring {aka   std :: __ cxx11 :: basic_string} 'requested        wstring exe="program";

error 2, because I must convert it to wchar_t, it is solved including the L:

in codeblocks I do not have any problem using it as a mingw compiler however with qt I use it as a visual studio compiler.

asked by Perl 15.02.2017 в 21:46

1 answer


For the first error, where you do string pro = "aplicacion"; , you should put:

   wstring pro = L"aplicacion";
// ^ una w       ^ una L"

For the following error, where you do

HANDLE hFile=CreateFile("C:/Users/Usuario/Desktop/aplicacion.exe", ...

you should do

HANDLE hFile=CreateFile(L"C:/Users/Usuario/Desktop/aplicacion.exe", ...
//                      ^ fijate en la L"

I do not have a Windows to confirm it, but those should be the solutions.

The problem lies in the definition or not of the macro UNICODE . If you do not define it, Windows uses the char * of all life, and you have no problems.

On the other hand, if you define it, Windows uses wchar_t * , wide characters , and those things happen. Notice that the second message says


argument '1' to 'void * CreateFileW (...

while you, in your code, call CreateFile( ) , without the W . That is an unmistakable symptom that you have defined UNICODE .

answered by 15.02.2017 / 22:01