But you need to be quick. This is the only way to guarantee that any error condition generated by the Win32 call you just made is in LastDllError . Let's leave this discussion of capturing Win32 error codes in VB with this outline. If lngErrVB is nonzero, then use it to report the error condition. If it's zero, check lngErr32 .
Chances are it's probably zero as well, but if it's nonzero, use it to report the error.
You should always use the value from LastDllError whenever possible. VB is making a conscious effort to intervene on your behalf, so this is your best bet for Win32 error codes. But as long as you try to find out as much as you can about what's going on underneath the scenes, you should be able to solve any problem. And yes, I did mention the save edict three times. You're throwing the safety net away when you tear into the Win32 APIs, so save your work before you try to run your code.