《Windows API》创建文件写入系统目录路径

UINT WINAPI GetSystemDirectory(
  _Out_ LPTSTR lpBuffer,
  _In_  UINT   uSize
);
#include
#include
#include

int main() {
    HANDLE hFile;
    TCHAR buffer[MAX_PATH];
    DWORD writeNum;
    GetSystemDirectoryA(buffer, MAX_PATH);
    hFile = CreateFile("haha.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile != INVALID_HANDLE_VALUE) {
        if (!WriteFile(hFile, buffer, lstrlen(buffer), &writeNum, NULL)) {
        }
        return GetLastError();
    }
    CloseHandle(hFile);
    system("pause");
    return 0;
}

你可能感兴趣的:(Windows,API)