@SLV: Thanks for your suggestions, feel free to update the code and upload it here when it's fixed. I personally detest SESE pretty much always, I only use it sometimes, but what's the point of generating a 10-layer deep if statement if you could simply do some checks and return false if something went wrong?
The only disadvantage is the possibility of handle/memory leaks, usually this can be resolved by writing a small class like this:
Code:
class Handle
{
public:
Handle(HANDLE h = 0)
{
mHandle = h;
}
~Handle()
{
DWORD dwFlags = 0;
if(GetHandleInformation(mHandle, &dwFlags) && !(dwFlags & HANDLE_FLAG_PROTECT_FROM_CLOSE))
CloseHandle(mHandle);
}
const HANDLE & operator=(const HANDLE & h)
{
return mHandle = h;
}
private:
HANDLE mHandle;
};
Which you can then use like this:
Code:
Handle hTest=CreateFileA("main.cpp", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
//do file operations
return 0;
EDIT: Some more information and opinions about SESE: http://stackoverflow.com/questions/12745412/single-entry-single-exit-rule