works fine on XP, but fails with Access Denied error on 2000. And this is not with a protected file here, but with any file I try! What should I do?Code:CreateFile(pszFile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, NULL);
works fine on XP, but fails with Access Denied error on 2000. And this is not with a protected file here, but with any file I try! What should I do?Code:CreateFile(pszFile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, NULL);
And so what are you expecting us to magic out of one line of code?
How did you declare ....
How did you initialise ....
Does it compile without any errors?
Have you been mucking about with ASCII/UNICODE?
What is the current directory?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
And so what are you expecting us to magic out of one line of code?
>> No, the code is so simple, thats the only line I could think that would be relevant.
How did you declare ....
>> Declare what exactly?
How did you initialise ....
>> Initialize what exactly?
Does it compile without any errors?
>> Of course.
Have you been mucking about with ASCII/UNICODE?
>> You mean combining them? No, the program is pure Unicode.
What is the current directory?
>> What ever the dir of the program I think, but it shouldn't make a difference anyway, pszFile is always an absolute path.
What might be relevant would be a small complete program which demonstrates the problem. As you seem to be saying it does it for all files, it should be about a 10 line program.
> thats the only line I could think that would be relevant.
http://www.catb.org/~esr/faqs/smart-....html#symptoms
> Initialize what exactly?
I dunno, let's say that pszFile is an array of 20 wide chars, and ypu've tried to put 50 in there.
Or it's just a pointer you didn't even bother to initialise before writing 50 chars.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
CreateFile has 7 parameters - not 6
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
> CreateFile has 7 parameters - not 6
ROFLMA - so it does!
> Does it compile without any errors?
> >> Of course.
Makes me wonder how this can be true then.
Seems like a typical garbage question. Just scribble down any old rubbish from memory rather than posting quality information like the actual code tried.
In too big a hurry to post something, anything, just get it posted and be damned the quality. Go waste someone elses time Yarin.
*PLONK*
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Hey Salem, take it easy. It was mistake.
Here's code:
As you can see, there are no memory overruns.Code:BOOL doMethod(wchar_t* pszFile) { HANDLE h = CreateFile(pszFile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); // All 7 params! :) if(h != INVALID_HANDLE_VALUE) { DWORD size = GetFileSize(h, NULL); DWORD a, rite = 0; BYTE buff[ME_BUFFSIZE]; ZeroMemory(buff, ME_BUFFSIZE); for(a = 0; a < size; a += ME_BUFFSIZE) WriteFile(h, buff, ME_BUFFSIZE, &rite, NULL); a = size - (a - ME_BUFFSIZE); if(a > 0) WriteFile(h, buff, a, &rite, NULL); CloseHandle(h); return TRUE; } return FALSE; } int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char* pcCommand, int nShow) { wchar_t buff[MAX_PATH]; lstrcpy(buff, L"\\\\?\\C:\\Documents and Settings\\Yarin\\Desktop\\TESTFILE.txt"); if(!doMethod(buff)) { if(GetLastError() == 5) Beep(2500, 100); } else Beep(1000, 50); return 0; }
> if(GetLastError() == 5)
Magic numbers, eh? You should know that magic numbers might change from OS to OS.
>> Magic numbers, eh? You should know that magic numbers might change from OS to OS.
I know, but I'm pretty sure Access Denied is 5 on 2000, XP, and Vista.
Not if the number is in the title. Doing extra work to look up what is the textual represention of the error takes time, time is money.
By the way, error codes don't change much between Windows versions, otherwise applications compiled under Win98 wouldn't run on XP. Somehow they do. That's because error codes are never replaced, but only added to the end or into empty gaps. And I have a feeling that ACCESS_DENIED error exists since the very first release of Windows.
Last edited by maxorator; 08-07-2008 at 04:07 AM.
I'm not sure what you mean about the number being in the title?
Macro & variable names can't be all numbers, and having a name like ACCESS_DENIED_5 is pointless.
If I see:
then I'd have to look up what 5 means (which wastes time), but if I see:Code:if ( GetLastError() == 5 )
I know exactly what the code is doing and don't have to waste any more time.Code:if ( GetLastError() == ACCESS_DENIED )