code listed here is Copyright 2009 Jim Michaels. some may have earlier copyright dates.
get 64-bit filesize from windows based on filename
//Copyright 2007,2009,2009 Jim Michaels
#include <windows.h>
LARGE_INTEGER li;
__int64 filesize64=0;
li.QuadPart=0;
HANDLE h=CreateFile(
lpFileName, // pointer to name of the file
GENERIC_READ, // access (read-write) mode
FILE_SHARE_READ, // share mode
NULL, // pointer to security attributes
OPEN_EXISTING, // how to create
FILE_ATTRIBUTE_NORMAL, // file attributes
INVALID_HANDLE_VALUE // handle to file with attributes to copy
);
if (INVALID_HANDLE_VALUE != h) {
DWORD d0, d1;
d0=GetFileSize(
h, // handle of file to get size of
&d1 // pointer to high-order word for file size
);
if (0xFFFFFFFF==d0) {
DWORD er=GetLastError();
if (NO_ERROR==er) {
li.LowPart=d0;
li.HighPart=(LONG)d1;
filesize64=li.QuadPart;
} else {
//ERROR: problem getting filesize.
}
}
CloseHandle(h);
} else {
//ERROR: could not open file.
}
//at this point, filesize is in both filesize64 and li.QuadPart
//for sprintf, use "%I64d"
for WinMain(), simulate/generate argc, argv from lpCmdLine parameter using an STL vector of strings.
//Copyright 2009 Jim Michaels
int argc;
//simulate command line
vector<string> argv;
int argvi=0; //argv index, used in place of argv++
string scmdline=lpCmdLine; //from WinMain() parameter
int argc;
int i1=0, i2=0;
while (i2 < scmdline.size()) {
//find first non-space
while ('\0'!=lpCmdLine[i1] && isspace(lpCmdLine[i1])) {
i1++;
i2++;
}
while ('\0'!=lpCmdLine[i2] && !isspace(lpCmdLine[i2])) {
i2++;
}
if (i2!=0 && i1!=i2) {
//we have an argument. push it on the vector/array.
if (lpCmdLine[i1]=='"' && lpCmdLine[i2-1]=='"') {
argv.push_back(scmdline.substr(i1+1, i2-i1-2));
} else {
argv.push_back(scmdline.substr(i1, i2-i1));
}
i1=i2; //i1 catch up to i2 now
}
}
argc=argv.size();