本文整理汇总了C++中GetFileSizeEx函数的典型用法代码示例。如果您正苦于以下问题:C++ GetFileSizeEx函数的具体用法?C++ GetFileSizeEx怎么用?C++ GetFileSizeEx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetFileSizeEx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FormatAttachmentPartHeader
BOOL CHttpRequestSender::CalcAttachmentPartSize(CString sName, LONGLONG& lSize)
{
lSize = 0;
CString sPartHeader;
BOOL bFormat = FormatAttachmentPartHeader(sName, sPartHeader);
if(!bFormat)
return FALSE;
lSize += sPartHeader.GetLength();
std::map<CString, CHttpRequestFile>::iterator it = m_Request.m_aIncludedFiles.find(sName);
if(it==m_Request.m_aIncludedFiles.end())
return FALSE;
CString sFileName = it->second.m_sSrcFileName.GetBuffer(0);
HANDLE hFile = CreateFile(sFileName,
GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
if(hFile==INVALID_HANDLE_VALUE)
{
return FALSE;
}
LARGE_INTEGER lFileSize;
BOOL bGetSize = GetFileSizeEx(hFile, &lFileSize);
if(!bGetSize)
{
CloseHandle(hFile);
return FALSE;
}
lSize += lFileSize.QuadPart;
CloseHandle(hFile);
CString sPartFooter;
bFormat = FormatAttachmentPartFooter(sName, sPartFooter);
if(!bFormat)
return FALSE;
lSize += sPartFooter.GetLength();
return TRUE;
}
示例2: CreateFile
LONG64 CCrashInfoReader::GetUncompressedReportSize(CErrorReportInfo& eri)
{
// Calculate summary size of all files included into crash report
LONG64 lTotalSize = 0;
std::map<CString, ERIFileItem>::iterator it;
HANDLE hFile = INVALID_HANDLE_VALUE;
CString sMsg;
BOOL bGetSize = FALSE;
LARGE_INTEGER lFileSize;
// Walk through all files in the crash report
for(it=eri.m_FileItems.begin(); it!=eri.m_FileItems.end(); it++)
{
// Get file name
CString sFileName = it->second.m_sSrcFile.GetBuffer(0);
// Check file exists
hFile = CreateFile(sFileName,
GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
if(hFile==INVALID_HANDLE_VALUE)
continue; // File does not exist
// Get file size
bGetSize = GetFileSizeEx(hFile, &lFileSize);
if(!bGetSize)
{
CloseHandle(hFile);
continue;
}
// Add to the sum
lTotalSize += lFileSize.QuadPart;
// Clean up
CloseHandle(hFile);
hFile = INVALID_HANDLE_VALUE;
}
// Return summary size
return lTotalSize;
}
示例3: MirrorSetAllocationSize
static int DOKAN_CALLBACK
MirrorSetAllocationSize(
LPCWSTR FileName,
LONGLONG AllocSize,
PDOKAN_FILE_INFO DokanFileInfo)
{
WCHAR filePath[MAX_PATH];
HANDLE handle;
LARGE_INTEGER fileSize;
GetFilePath(filePath, MAX_PATH, FileName);
DbgPrint(L"SetAllocationSize %s, %I64d\n", filePath, AllocSize);
handle = (HANDLE)DokanFileInfo->Context;
if (!handle || handle == INVALID_HANDLE_VALUE) {
DbgPrint(L"\tinvalid handle\n\n");
return -1;
}
if (GetFileSizeEx(handle, &fileSize)) {
if (AllocSize < fileSize.QuadPart) {
fileSize.QuadPart = AllocSize;
if (!SetFilePointerEx(handle, fileSize, NULL, FILE_BEGIN)) {
DbgPrint(L"\tSetAllocationSize: SetFilePointer eror: %d, "
L"offset = %I64d\n\n", GetLastError(), AllocSize);
return GetLastError() * -1;
}
if (!SetEndOfFile(handle)) {
DWORD error = GetLastError();
DbgPrint(L"\terror code = %d\n\n", error);
return error * -1;
}
}
} else {
DWORD error = GetLastError();
DbgPrint(L"\terror code = %d\n\n", error);
return error * -1;
}
return 0;
}
示例4: FindProcessId
DWORD FindProcessId (DWORD jobNumber)
/* Obtain the process ID of the specified job number. */
{
HANDLE hJobData;
JM_JOB jobRecord;
DWORD nXfer, fileSizeLow;
TCHAR jobMgtFileName[MAX_PATH+1];
OVERLAPPED regionStart;
LARGE_INTEGER fileSize;
if ( !GetJobMgtFileName (jobMgtFileName) ) return 0;
hJobData = CreateFile (jobMgtFileName, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hJobData == INVALID_HANDLE_VALUE) return 0;
/* Position to the correct record, but not past the end of file */
/* As a variation, use GetFileSize to demonstrate its operation. */
if (!GetFileSizeEx (hJobData, &fileSize) ||
(fileSize.HighPart != 0 || SJM_JOB * (jobNumber - 1) > fileSize.LowPart
|| fileSize.LowPart > SJM_JOB * MAX_JOBS_ALLOWED))
return 0;
fileSizeLow = fileSize.LowPart;
/* SetFilePoiner is more convenient here than SetFilePointerEx since the the file is known to be "short" ( < 4 GB). */
SetFilePointer (hJobData, SJM_JOB * (jobNumber - 1), NULL, FILE_BEGIN);
/* Get a shared lock on the record. */
regionStart.Offset = SJM_JOB * (jobNumber - 1);
regionStart.OffsetHigh = 0; /* Assume a "short" file. */
regionStart.hEvent = (HANDLE)0;
LockFileEx (hJobData, 0, 0, SJM_JOB, 0, ®ionStart);
if (!ReadFile (hJobData, &jobRecord, SJM_JOB, &nXfer, NULL))
ReportError (_T ("JobData file error"), 0, TRUE);
UnlockFileEx (hJobData, 0, SJM_JOB, 0, ®ionStart);
CloseHandle (hJobData);
return jobRecord.ProcessId;
}
示例5: _zip_stat_win32
static int
_zip_stat_win32(HANDLE h, zip_stat_t *st, _zip_source_win32_read_file_t *ctx)
{
FILETIME mtimeft;
time_t mtime;
LARGE_INTEGER size;
int regularp;
if (!GetFileTime(h, NULL, NULL, &mtimeft)) {
zip_error_set(&ctx->error, ZIP_ER_READ, _zip_win32_error_to_errno(GetLastError()));
return -1;
}
if (_zip_filetime_to_time_t(mtimeft, &mtime) < 0) {
zip_error_set(&ctx->error, ZIP_ER_READ, ERANGE);
return -1;
}
regularp = 0;
if (GetFileType(h) == FILE_TYPE_DISK) {
regularp = 1;
}
if (!GetFileSizeEx(h, &size)) {
zip_error_set(&ctx->error, ZIP_ER_READ, _zip_win32_error_to_errno(GetLastError()));
return -1;
}
zip_stat_init(st);
st->mtime = mtime;
st->valid |= ZIP_STAT_MTIME;
if (ctx->end != 0) {
st->size = ctx->end - ctx->start;
st->valid |= ZIP_STAT_SIZE;
}
else if (regularp) {
st->size = (zip_uint64_t)size.QuadPart;
st->valid |= ZIP_STAT_SIZE;
}
return 0;
}
示例6: uGetFileSize
int uGetFileSize(UFile fd, __int64 * file_size, sys_call_error_fun fun)
{
#ifdef _WIN32
LARGE_INTEGER size;
BOOL res = GetFileSizeEx(fd, &size);
if (res == 0)
sys_call_error("GetFileSizeEx");
else
*file_size = size.QuadPart;
return res;
#else
struct stat64 buf;
if (fstat64(fd, &buf) == -1)
{
sys_call_error("fstat64");
return 0;
}
*file_size = buf.st_size;
return 1;
#endif
}
示例7: GetFileSizeEx
::FLAC__StreamDecoderLengthStatus
OurDecoder::length_callback(FLAC__uint64 *stream_length)
{
#ifdef PRWIN_ENV
LARGE_INTEGER lpos;
BOOL result = GetFileSizeEx(_fp, &lpos);
*stream_length = lpos.QuadPart;
return (result ? FLAC__STREAM_DECODER_LENGTH_STATUS_OK : FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR);
#else
SInt64 fork_size = 0;
OSErr result = FSGetForkSize(CAST_REFNUM(_fp), &fork_size);
*stream_length = fork_size;
return (result == noErr ? FLAC__STREAM_DECODER_LENGTH_STATUS_OK : FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR);
#endif
}
示例8: getFileSize
LONGLONG getFileSize(HANDLE hFile)
{
LARGE_INTEGER lpFileSize = {0};
if ((hFile != INVALID_HANDLE_VALUE) && (hFile != 0))
{
if (!GetFileSizeEx(hFile, &lpFileSize))
{
MessageBox(0, TEXT("GetFileSizeEx failed"), TEXT("Error"), MB_ICONERROR);
return 0;
}
else
{
return lpFileSize.QuadPart;
}
}
else
{
return 0;
}
}
示例9: sizeof
size_t File::GetFileSize()
{
if( !IsValidHandle() )
return 0;
size_t Size = 0;
#if _WIN32 || _WIN64
LARGE_INTEGER LInt;
Memory::Memzero( &LInt, sizeof(LInt) );
GetFileSizeEx( m_file_handle, &LInt );
Size = (size_t) LInt.QuadPart;
//DWORD dwSize = GetFileSize( m_hFile, NULL );
#else
size_t Pos = ftell(m_file_handle);
fseek( m_file_handle, 0, SEEK_END );
Size = ftell(m_file_handle);
fseek( m_file_handle, Pos, SEEK_SET );
#endif
return Size;
}
示例10: Destroy
BOOL CFileMemoryMapping::Init(LPCTSTR szFileName)
{
if(m_hFile!=INVALID_HANDLE_VALUE)
{
// If a file mapping already created, destroy it
Destroy();
}
// Open file handle
m_hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
if(m_hFile == INVALID_HANDLE_VALUE)
return FALSE;
// Create file mapping
m_hFileMapping = CreateFileMapping(m_hFile, 0, PAGE_READONLY, 0, 0, 0);
LARGE_INTEGER size;
GetFileSizeEx(m_hFile, &size);
m_uFileLength = size.QuadPart;
return TRUE;
}
示例11: LoadFile
//Return the contents of a text file
void LoadFile(char *path, DataFile *dataFile)
{
HANDLE fileHandle = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
if (fileHandle != INVALID_HANDLE_VALUE)
{
LARGE_INTEGER fileSize;
if (GetFileSizeEx(fileHandle, &fileSize))
{
unsigned int fileSize_32bit = (unsigned int)fileSize.QuadPart;
dataFile->Data = VirtualAlloc(0, fileSize_32bit, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (dataFile->Data)
{
DWORD bytesRead;
if (ReadFile(fileHandle, dataFile->Data, fileSize_32bit, &bytesRead, NULL) && fileSize_32bit == bytesRead)
{
dataFile->Length = fileSize_32bit;
}
else
{
//Failed to read file
}
}
else
{
//Failed to allocate memory
}
}
else
{
//Failed to get file size
}
}
else
{
//Failed to create file handle
}
}
示例12: path_get_size
/* return the size of a given file in '*psize'. returns 0 on
* success, -1 on failure (error code in errno) */
APosixStatus
path_get_size( const char* path, uint64_t *psize )
{
#ifdef _WIN32
/* avoid _stat64 which is only defined in MSVCRT.DLL, not CRTDLL.DLL */
/* do not use OpenFile() because it has strange search behaviour that could */
/* result in getting the size of a different file */
LARGE_INTEGER size;
HANDLE file = CreateFile( /* lpFilename */ path,
/* dwDesiredAccess */ GENERIC_READ,
/* dwSharedMode */ FILE_SHARE_READ|FILE_SHARE_WRITE,
/* lpSecurityAttributes */ NULL,
/* dwCreationDisposition */ OPEN_EXISTING,
/* dwFlagsAndAttributes */ 0,
/* hTemplateFile */ NULL );
if (file == INVALID_HANDLE_VALUE) {
/* ok, just to play fair */
errno = ENOENT;
return -1;
}
if (!GetFileSizeEx(file, &size)) {
/* maybe we tried to get the size of a pipe or something like that ? */
*psize = 0;
}
else {
*psize = (uint64_t) size.QuadPart;
}
CloseHandle(file);
return 0;
#else
int ret;
struct stat st;
CHECKED(ret, stat(path, &st));
if (ret == 0) {
*psize = (uint64_t) st.st_size;
}
return ret;
#endif
}
示例13: _lws_plat_file_open
LWS_VISIBLE lws_fop_fd_t
_lws_plat_file_open(const struct lws_plat_file_ops *fops, const char *filename,
const char *vpath, lws_fop_flags_t *flags)
{
HANDLE ret;
WCHAR buf[MAX_PATH];
lws_fop_fd_t fop_fd;
LARGE_INTEGER llFileSize = {0};
MultiByteToWideChar(CP_UTF8, 0, filename, -1, buf, ARRAY_SIZE(buf));
if (((*flags) & 7) == _O_RDONLY) {
ret = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
} else {
ret = CreateFileW(buf, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
}
if (ret == LWS_INVALID_FILE)
goto bail;
fop_fd = malloc(sizeof(*fop_fd));
if (!fop_fd)
goto bail;
fop_fd->fops = fops;
fop_fd->fd = ret;
fop_fd->filesystem_priv = NULL; /* we don't use it */
fop_fd->flags = *flags;
fop_fd->len = GetFileSize(ret, NULL);
if(GetFileSizeEx(ret, &llFileSize))
fop_fd->len = llFileSize.QuadPart;
fop_fd->pos = 0;
return fop_fd;
bail:
return NULL;
}
示例14: AddError
bool LWOFile::LoadFromFile(const char *strFile)
{
// try to open file
HANDLE hFile=CreateFileA(strFile, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile==INVALID_HANDLE_VALUE)
{
AddError("Could not open file: " + std::string(strFile));
return false;
}
// get file size
LARGE_INTEGER LI_Size;
if(!GetFileSizeEx(hFile,&LI_Size))
{
AddError("Could not get file size!");
return false;
}
unsigned int iFileSize=(unsigned int)LI_Size.QuadPart;
// allocate memory to hold the file
char *pData=new char[iFileSize];
// read file to memory
DWORD iBytesRead=0;
if(!ReadFile(hFile,pData,iFileSize,&iBytesRead,NULL) || iBytesRead!=iFileSize)
{
AddError("Reading file failed!");
delete[] pData;
CloseHandle(hFile);
return false;
}
// load
if(!LoadFromMemory(pData, iFileSize)) return false;
delete[] pData;
CloseHandle(hFile);
return true;
}
示例15: kull_m_file_readData
BOOL kull_m_file_readData(PCWCHAR fileName, PBYTE * data, PDWORD lenght) // for little files !
{
BOOL reussite = FALSE;
DWORD dwBytesReaded;
LARGE_INTEGER filesize;
HANDLE hFile = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if(hFile && hFile != INVALID_HANDLE_VALUE)
{
if(GetFileSizeEx(hFile, &filesize) && !filesize.HighPart)
{
*lenght = filesize.LowPart;
if(*data = (PBYTE) LocalAlloc(LPTR, *lenght))
{
if(!(reussite = ReadFile(hFile, *data, *lenght, &dwBytesReaded, NULL) && (*lenght == dwBytesReaded)))
LocalFree(*data);
}
}
CloseHandle(hFile);
}
return reussite;
}