#include <windows.h>
#include <iostream>
using namespace std;
int main() {
char* file="d:/tester";
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(file, &FindFileData); // line of error says argument of type char* is incompatible with parameter of type LPCWSTR
}
I can't understand the error.What is it and how can I solve the error?
I am making a console app and need to check if files are in there in the directory .
the type LPCWSTR
is a const pointer to wide char
the file
in char* file="d:/tester";
is a pointer to an ordinary char
Ordinary char usually uses 1 byte of memory, while wide char usually uses 2 bytes. What will happen if the file name contains cyrillic or japanese letters? You will not be able to open it without specifying the encoding. Windows API accepts wide chars to FindFirstFile
function, because file name can be in a unicode. So, if you write L"foo_bar"
the compiler will interpret it as wide character string. Therefore you can write wchar_t* file = L"d:\\tester";
to match parameter types, so compilation will be successful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With