Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetLastError always returns 0

Status
Not open for further replies.

Idiota

Programmer
Dec 18, 2002
11
0
0
AR
Hi. I have this in my program:

Code:
Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Public Declare Function GetLastError Lib "kernel32" () As Long
Public Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

Just from the API viewer.

Problem is, when the copyFile or DeleteFile fail (they return 0) the getLastError function always returns 0!!! It's useless that way.

Do you have any idea?

Thank you very much,

Daniel
 
According to my reference, it says:

"Use the LastDLLError property of the Err object to obtain the GetLastError value in Visual Basic. This is necessary because VB sometimes resets the GetLastError value between the time the API call that generated the error returns, and the time your VB program continues."

Try that and see if it works,

Robert
 
Hi! This worked great.
Thank you very much, you are my favorite Vampire of the day!

Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top