digitalmars.D - FileApi.h
- Ruby The Roobster (234/234) Dec 11 2020 So, there is an issue. There is no D version for FileApi.h So,
- rikki cattermole (3/3) Dec 11 2020 They have somehow ended up in winbase i.e.
- Ruby The Roobster (4/7) Dec 11 2020 Okay. I see. Whoops. Didn't know it was all in winbase.d Thanks
- Kagamin (2/2) Dec 11 2020 At some point windows sdk was refactored and code ended up in
So, there is an issue. There is no D version for FileApi.h So, for people who want to use that file(which includes me) here is it translated into D. I would also like to add that there are two files included in the original that are not translated into D yet: minwindef.h and winwinbase.h. Enjoy, and tell me if anything is not working! import core.sys.windows.winbase; import core.sys.windows.windef; public const uint CREATE_NEW = 1; public const uint CREATE_ALWAYS = 2; public const uint OPEN_EXISTING = 3; public const uint OPEN_ALWAYS = 4; public const uint TRUNCATE_EXISTING = 5; public const DWORD INVALID_FILE_SIZE = 0xffffffff; public const DWORD INVALID_SET_FILE_POINTER = -1; public const DWORD INVALID_FILE_ATTRIBUTES = -1; extern(Windows) public HANDLE CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); extern(Windows) public DWORD GetFileAttributesW (LPCWSTR lpFileName); extern(Windows) public DWORD GetFileSize (HANDLE hFile, LPDWORD lpFileSizeHigh); extern(Windows) public DWORD SetFilePointer (HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod); public struct BY_HANDLE_FILE_INFORMATION { DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD dwVolumeSerialNumber; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD nNumberOfLinks; DWORD nFileIndexHigh; DWORD nFileIndexLow; }; extern(Windows) public LONG CompareFileTime (const FILETIME *lpFileTime1, const FILETIME *lpFileTime2); extern(Windows) public HANDLE CreateFileA (LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); extern(Windows) public WINBOOL DefineDosDeviceW (DWORD dwFlags, LPCWSTR lpDeviceName, LPCWSTR lpTargetPath); extern(Windows) public WINBOOL DeleteVolumeMountPointW (LPCWSTR lpszVolumeMountPoint); extern(Windows) public WINBOOL FileTimeToLocalFileTime (const FILETIME *lpFileTime, LPFILETIME lpLocalFileTime); extern(Windows) public WINBOOL FindCloseChangeNotification (HANDLE hChangeHandle); extern(Windows) public HANDLE FindFirstChangeNotificationA (LPCSTR lpPathName, WINBOOL bWatchSubtree, DWORD dwNotifyFilter); extern(Windows) public HANDLE FindFirstChangeNotificationW (LPCWSTR lpPathName, WINBOOL bWatchSubtree, DWORD dwNotifyFilter); extern(Windows) public HANDLE FindFirstFileA (LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData); extern(Windows) public HANDLE FindFirstFileW (LPCWSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData); extern(Windows) public HANDLE FindFirstVolumeW (LPWSTR lpszVolumeName, DWORD cchBufferLength); extern(Windows) public WINBOOL FindNextChangeNotification (HANDLE hChangeHandle); extern(Windows) public WINBOOL FindNextVolumeW (HANDLE hFindVolume, LPWSTR lpszVolumeName, DWORD cchBufferLength); extern(Windows) public WINBOOL FindVolumeClose (HANDLE hFindVolume); extern(Windows) public WINBOOL GetDiskFreeSpaceA (LPCSTR lpRootPathName, LPDWORD lpSectorsPerCluster, LPDWORD lpBytesPerSector, LPDWORD lpNumberOfFreeClusters, LPDWORD lpTotalNumberOfClusters); extern(Windows) public WINBOOL GetDiskFreeSpaceW (LPCWSTR lpRootPathName, LPDWORD lpSectorsPerCluster, LPDWORD lpBytesPerSector, LPDWORD lpNumberOfFreeClusters, LPDWORD lpTotalNumberOfClusters); extern(Windows) public UINT GetDriveTypeA (LPCSTR lpRootPathName); extern(Windows) public UINT GetDriveTypeW (LPCWSTR lpRootPathName); extern(Windows) public DWORD GetFileAttributesA (LPCSTR lpFileName); extern(Windows) public WINBOOL GetFileInformationByHandle (HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation); extern(Windows) public WINBOOL GetFileSizeEx (HANDLE hFile, PLARGE_INTEGER lpFileSize); extern(Windows) public WINBOOL GetFileTime (HANDLE hFile, LPFILETIME lpCreationTime, LPFILETIME lpLastAccessTime, LPFILETIME lpLastWriteTime); extern(Windows) public DWORD GetFileType (HANDLE hFile); extern(Windows) public DWORD GetFullPathNameA (LPCSTR lpFileName, DWORD nBufferLength, LPSTR lpBuffer, LPSTR *lpFilePart); extern(Windows) public DWORD GetFullPathNameW (LPCWSTR lpFileName, DWORD nBufferLength, LPWSTR lpBuffer, LPWSTR *lpFilePart); extern(Windows) public DWORD GetLogicalDrives (); extern(Windows) public DWORD GetLogicalDriveStringsW (DWORD nBufferLength, LPWSTR lpBuffer); extern(Windows) public DWORD GetLongPathNameA (LPCSTR lpszShortPath, LPSTR lpszLongPath, DWORD cchBuffer); extern(Windows) public DWORD GetLongPathNameW (LPCWSTR lpszShortPath, LPWSTR lpszLongPath, DWORD cchBuffer); extern(Windows) public DWORD GetShortPathNameW (LPCWSTR lpszLongPath, LPWSTR lpszShortPath, DWORD cchBuffer); extern(Windows) public UINT GetTempFileNameW (LPCWSTR lpPathName, LPCWSTR lpPrefixString, UINT uUnique, LPWSTR lpTempFileName); extern(Windows) public WINBOOL GetVolumeInformationW (LPCWSTR lpRootPathName, LPWSTR lpVolumeNameBuffer, DWORD nVolumeNameSize, LPDWORD lpVolumeSerialNumber, LPDWORD lpMaximumComponentLength, LPDWORD lpFileSystemFlags, LPWSTR lpFileSystemNameBuffer, DWORD nFileSystemNameSize); extern(Windows) public WINBOOL GetVolumePathNameW (LPCWSTR lpszFileName, LPWSTR lpszVolumePathName, DWORD cchBufferLength); extern(Windows) public WINBOOL LocalFileTimeToFileTime (const FILETIME *lpLocalFileTime, LPFILETIME lpFileTime); extern(Windows) public WINBOOL LockFile (HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh); extern(Windows) public DWORD QueryDosDeviceW (LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax); extern(Windows) public WINBOOL ReadFileEx (HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); extern(Windows) public WINBOOL ReadFileScatter (HANDLE hFile, FILE_SEGMENT_ELEMENT[] aSegmentArray, DWORD nNumberOfBytesToRead, LPDWORD lpReserved, LPOVERLAPPED lpOverlapped); extern(Windows) public WINBOOL SetFileTime (HANDLE hFile, const FILETIME *lpCreationTime, const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime); extern(Windows) public WINBOOL SetFileValidData (HANDLE hFile, LONGLONG ValidDataLength); extern(Windows) public WINBOOL UnlockFile (HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh); extern(Windows) public WINBOOL WriteFileEx (HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); extern(Windows) public WINBOOL WriteFileGather (HANDLE hFile, FILE_SEGMENT_ELEMENT[] aSegmentArray, DWORD nNumberOfBytesToWrite, LPDWORD lpReserved, LPOVERLAPPED lpOverlapped); extern(Windows) public WINBOOL GetVolumeNameForVolumeMountPointW (LPCWSTR lpszVolumeMountPoint, LPWSTR lpszVolumeName, DWORD cchBufferLength); extern(Windows) public WINBOOL GetVolumePathNamesForVolumeNameW (LPCWSTR lpszVolumeName, LPWCH lpszVolumePathNames, DWORD cchBufferLength, PDWORD lpcchReturnLength); extern(Windows) public DWORD GetFinalPathNameByHandleA (HANDLE hFile, LPSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags); extern(Windows) public DWORD GetFinalPathNameByHandleW (HANDLE hFile, LPWSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags); extern(Windows) public DWORD GetVolumeInformationByHandleW (HANDLE hFile, LPWSTR lpVolumeNameBuffer, DWORD nVolumeNameSize, LPDWORD lpVolumeSerialNumber, LPDWORD lpMaximumComponentLength, LPDWORD lpFileSystemFlags, LPWSTR lpFileSystemNameBuffer, DWORD nFileSystemNameSize); struct WIN32_FILE_ATTRIBUTE_DATA { DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; }; struct CREATEFILE2_EXTENDED_PARAMETERS { DWORD dwSize; DWORD dwFileAttributes; DWORD dwFileFlags; DWORD dwSecurityQosFlags; LPSECURITY_ATTRIBUTES lpSecurityAttributes; HANDLE hTemplateFile; }; extern(Windows) public WINBOOL CreateDirectoryA (LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes); extern(Windows) public WINBOOL CreateDirectoryW (LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes); extern(Windows) public WINBOOL DeleteFileA (LPCSTR lpFileName); extern(Windows) public WINBOOL DeleteFileW (LPCWSTR lpFileName); extern(Windows) public WINBOOL FindClose (HANDLE hFindFile); extern(Windows) public HANDLE FindFirstFileExA (LPCSTR lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, LPVOID lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, LPVOID lpSearchFilter, DWORD dwAdditionalFlags); extern(Windows) public WINBOOL FindNextFileA (HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData); extern(Windows) public WINBOOL FindNextFileW (HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData); extern(Windows) public WINBOOL FlushFileBuffers (HANDLE hFile); extern(Windows) public WINBOOL GetDiskFreeSpaceExA (LPCSTR lpDirectoryName, PULARGE_INTEGER lpFreeBytesAvailableToCaller, PULARGE_INTEGER lpTotalNumberOfBytes, PULARGE_INTEGER lpTotalNumberOfFreeBytes); extern(Windows) public WINBOOL GetDiskFreeSpaceExW (LPCWSTR lpDirectoryName, PULARGE_INTEGER lpFreeBytesAvailableToCaller, PULARGE_INTEGER lpTotalNumberOfBytes, PULARGE_INTEGER lpTotalNumberOfFreeBytes); extern(Windows) public DWORD GetFileType (HANDLE hFile); extern(Windows) public WINBOOL GetFileAttributesExA (LPCSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation); extern(Windows) public WINBOOL GetFileAttributesExW (LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation); extern(Windows) public DWORD GetTempPathW (DWORD nBufferLength, LPWSTR lpBuffer); extern(Windows) public WINBOOL LockFileEx (HANDLE hFile, DWORD dwFlags, DWORD dwReserved, DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, LPOVERLAPPED lpOverlapped); extern(Windows) public WINBOOL ReadFile (HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped); extern(Windows) public WINBOOL RemoveDirectoryA (LPCSTR lpPathName); extern(Windows) public WINBOOL RemoveDirectoryW (LPCWSTR lpPathName); extern(Windows) public WINBOOL SetEndOfFile (HANDLE hFile); extern(Windows) public WINBOOL SetFileAttributesA (LPCSTR lpFileName, DWORD dwFileAttributes); extern(Windows) public WINBOOL SetFileAttributesW (LPCWSTR lpFileName, DWORD dwFileAttributes); extern(Windows) public WINBOOL SetFilePointerEx (HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod); extern(Windows) public WINBOOL UnlockFileEx (HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped); extern(Windows) public WINBOOL WriteFile (HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped); extern(Windows) public HANDLE CreateFile2 (LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwCreationDisposition, CREATEFILE2_EXTENDED_PARAMETERS pCreateExParams); For people who want to know, this is based off of this file: https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-headers/include/fileapi.h
Dec 11 2020
They have somehow ended up in winbase i.e. https://github.com/dlang/druntime/blob/a7915d60c8d5ebff4f79eb48a8c52e779d1dc176/src/core/sys/windows/winbase.d#L1740 This should be fixed in druntime.
Dec 11 2020
On Friday, 11 December 2020 at 12:50:56 UTC, rikki cattermole wrote:They have somehow ended up in winbase i.e. https://github.com/dlang/druntime/blob/a7915d60c8d5ebff4f79eb48a8c52e779d1dc176/src/core/sys/windows/winbase.d#L1740 This should be fixed in druntime.Okay. I see. Whoops. Didn't know it was all in winbase.d Thanks for the info.
Dec 11 2020
At some point windows sdk was refactored and code ended up in different places.
Dec 11 2020