1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #include <iostream>
#include <string>
#include <windows.h>
#define TESTFILE "toto.txt"
#define FULL_PATH_VERSION FALSE
int main()
{
char buffer[MAX_PATH];
GetCurrentDirectory(sizeof(buffer), buffer);
std::string path(buffer);
std::cout << "CurrentDirectory : " << path << std::endl;
if (FULL_PATH_VERSION) {
if (*path.rbegin() != '\\')
path.append("\\");
path.append(TESTFILE);
} else {
path = TESTFILE;
}
std::cout << "TestFile : " << path << std::endl;
if (!SetFileAttributes(path.c_str(), FILE_ATTRIBUTE_HIDDEN))
{
DWORD dwError = GetLastError();
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buffer,
sizeof(buffer),
NULL
);
CharToOemBuff(buffer, buffer, sizeof(buffer));
std::cout << "Err no. " << dwError << " : " << buffer << std::endl;
}
return 0;
} |
Partager