News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

while using CopyFile........

Started by shaikkareem, March 28, 2014, 10:33:09 PM

Previous topic - Next topic

shaikkareem

here i'm in situation like never faced before.....that i'm using the program
   include \masm32\include\masm32rt.inc


   .data
   oldfile db 'G:\Images\325837.jpg',0
   newfile db 'forget.jpg',0


   .data?




   .code
start:
   cls

   invoke CopyFile,offset oldfile,offset newfile,FALSE
   print str$(eax),13,10

   invoke GetLastError
   print str$(eax),13,10



exit

end start


thats like that i compile , link it and runt it without any problem running successfully. actually it done its work perfectly..but while using copyfile function in middle of a big program it is giving trouble it is not copying and returning error code 5. in two or five line code it is perfect but in among lots of instructions it is not going well as it in here...can any body tell me what is going on ............ my experience is at the top of all instructions in a big program its running well but putting it middle in that program returnig error code 5............thats it

GoneFishing

As described on MSDN:
QuoteReturn value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.
Did you try to call  LastError$ macro in "a big program" ? If so what did it say?

[EDIT]: From the list of System Error Codes (0-499):
Quote
ERROR_ACCESS_DENIED
5 (0x5)
Access is denied.
No mysteries - check permissions

shaikkareem

If as you said it failed due to 'error access denied' then why it is succeeding at top of 'the big program', i'm not tried that macro yet. just justify this one before that......

dedndave

are you trying to copy to or from a network drive ?

GoneFishing

Quote from: shaikkareem on March 29, 2014, 03:26:55 AM
If as you said it failed due to 'error access denied' then why it is succeeding at top of 'the big program'...

It's hard to say without "a big program" source code  ;)

shaikkareem

Quote from: dedndave on March 29, 2014, 03:46:55 AM
are you trying to copy to or from a network drive ?

no i'm not, i'm just copying from removable media(pendrive) to my local disk thats it ......

shaikkareem

Quote from: vertograd on March 29, 2014, 03:47:20 AM
Quote from: shaikkareem on March 29, 2014, 03:26:55 AM
If as you said it failed due to 'error access denied' then why it is succeeding at top of 'the big program'...

It's hard to say without "a big program" source code  ;)


it is really returning with 'access is denied' when i called LastError$ what i've to do

sinsi

Check to see what the current directory is - you give a full path for the source but only a name for the destination.
If you change directories to e.g. a CD or C:\Windows then you would most likely get "access denied".
🍺🍺🍺

jj2007

Quote from: shaikkareem on March 29, 2014, 02:41:06 PM
it is really returning with 'access is denied' when i called LastError$ what i've to do

What do you do if you put the key into your door, and it won't open?
- call the police?
- ask for help in a forum?
- or try to find out why the key doesn't open the door??

The message is utterly clear: ACCESS DENIED. You are not allowed to copy file A to destination B.

Check if you can copy that particular file to destination B using Windows Explorer. And read carefully what sinsi wrote above.

If that still doesn't help, use this snippet to test where is your file's destination.

include \masm32\include\masm32rt.inc

.data?
buffer   db MAX_PATH dup(?)

.code
start:
   push eax
   invoke GetFullPathName, chr$("AnyFile.txt"), sizeof buffer, addr buffer, esp
   pop edx
   print offset buffer
   exit
end start

dedndave

check the destination folder, right-click, properties
see if your user account has write permission on that folder

MichaelW

Quote from: shaikkareem on March 28, 2014, 10:33:09 PM
but while using copyfile function in middle of a big program it is giving trouble it is not copying and returning error code 5.

CopyFile does not return error code 5 it returns non-zero for success or zero for failure. The last-error code value is meaningful only when a function that sets the last-error code value returns failure. If you are calling GetLastError without first determining that CopyFile failed, the returned last-error code value could be a leftover from some other function call.
Well Microsoft, here's another nice mess you've gotten us into.

jj2007

Quote from: MichaelW on March 29, 2014, 03:59:52 PM
CopyFile does not return error code 5 it returns non-zero for success or zero for failure. The last-error code value is meaningful only when a function that sets the last-error code value returns failure. If you are calling GetLastError without first determining that CopyFile failed, the returned last-error code value could be a leftover from some other function call.

Perfectly right, of course, although it seems that OP does check for return code:

   invoke CopyFile,offset oldfile,offset newfile,FALSE
   print str$(eax),13,10   <<<<<<<<<<<<< OP, what do you see here???
   invoke GetLastError

MichaelW

Quotealthough it seems that OP does check for return code

Yes, in the code that is functioning correctly, but not necessarily in the big program where it is giving trouble, and also where there are more potential errors.
Well Microsoft, here's another nice mess you've gotten us into.

sinsi


   print str$(eax),13,10   <<<<<<<<<<<<< OP, what do you see here???
   invoke GetLastError

Swap those two lines maybe? The macros probably use APIs that set the last error code.



🍺🍺🍺

shaikkareem

thank you all................the problem is with restriction of access to removable disk. that is i just open the removable disk with un-proper access rights (stupid)......just closed it by adding additional access rights and the denying access problem closed with it, things are good now,.,.,.,.,.,.,.,..,, :icon_rolleyes: