"TC" <a@b.c.d> wrote in news:1069473807.510665@teuthos:
[color=blue]
>
> "Lyle Fairfield" <MissingAddress@Invalid.Com> wrote in message
> news:Xns943A39FDFC43CFFDBA@130.133.1.4...[color=green]
>>
aatcbbtccctc@yahoo.com (TC) wrote in news:be37bfe0.0311202128.62ac0124
>> @posting.google.com:
>>[color=darkred]
>> > Lyle Fairfield <MissingAddress@Invalid.Com> wrote in message news:[/color]
>> <Xns9439A9A7158B2FFDBA@130.133.1.4>...[color=darkred]
>> > (snip)
>> >
>> >> If one gets a zero (false) one can call
>> >> GetLastError to see just what the problem is.
>> >
>> >
>> > Not so in VBA. The value of GetLastError will have been altered by
>> > other calls that VBA makes "behind the scenes" when returning from
>> > the DLL call.
>> >
>> > You must always use Err.LastDLLError to check the result of DLL calls
>> > from VBA. VBA saves the correct GetLastError value in that property
>> > of the error object, for that purpose.
>> >
>> > TC[/color]
>>
>> I think your statement may be too strong. In the case of the Wininet
>> Functions GetLastError seems to return the same value as
>> Err.LastDllError. (Has Err always had the LastDllError Property? I do
>> not know. The code I posted is several years old. I recall thinking I
>> needed to use[/color]
> LastDllError[color=green]
>> and then discarding that notion, but I can't remember why.). But I have
>> tested my assertion specifically only with[/color]
>
> (snip code)
>
>
> You may have just been lucky!
>
> A few minutes googling gave the following.
>
>
>
http://msdn.microsoft.com/library/de...en-us/debug/ba
> se/ getlasterror.asp
> "Visual Basic: Applications should call err.LastDllError instead of
> GetLastError."
>
>
http://www.partware.com/ebooks/api/r...lasterror.html
> "Although GetLastError works perfectly in Visual Basic, it will
> sometimes not appear to work. This is because Visual Basic implicitly
> uses the API frequently to perform tasks which are seemingly intrinsic
> to the language. These hidden API function calls will usually overwrite
> the error code which your code may be trying to read. To compensate for
> this, the LastDllError property of the Err object, predefined in Visual
> Basic, caches the error code from the last API function explicitly
> called by your program. You should use the expression Err.LastDllError
> instead of the GetLastError function to debug failed API function
> calls."
>
>
http://www.google.com.au/search?q=ca...ip.com/books/1
> 861
> 002432/chapter_2432_03.asp+getlasterror++lastdllerr+OR+la stdllerror&hl=en
> &ie
>=UTF-8
> "Internally, VB is making Win32 calls all the time in your application.
> Sometimes, when you make a Win32 call, this may trigger an event within
> your application that causes VB to make other Win32 calls (we'll address
> window messages later on in the book). Well, what happens if your
> initial call causes an error, but the internal Win32 call made by VB
> clears out the value of the error? You get the situation that we just
> saw. GetLastError returns a zero, but Err.LastDllError returns the
> correct error code. In previous versions of VB, the LastDllError
> property didn't exist, and strange situations like the one we just saw
> popped up again and again. Therefore, the VB designers decided to add
> the LastDllError to the Err object. This property should be used when a
> Win32 call is made that causes an error, because VB will track your
> Win32 call and make sure that this property reflects any possible error
> conditions."
>
>
http://www.mvps.org/vb/index2.html?t...matmessage.htm
> "It can be frustrating looking up values returned by Err.LastDllError,
> to be sure. What's that? You use GetLastError? As much as I hate to tell
> you, that's really not very smart. You see, the way Microsoft designed
> VB, there's a whole lotta API calls going on behind your back There's no
> guarantee that calling GetLastError will result in that set by the API
> call you made."
>
> Cheers,
> TC[/color]
Probably I wrote this before LastDllError existed and were I to start
again, Probably I would use LastDllError.
On the other hand I am not a supporter of Googling to substantiate any
claim. Often the stuff found is wrong, less often for MVPs sites. I've
almost completely given up on instructions about using API functions in
VBA. I tend to munge the C++ code found in its include files.
As I explained, my application has stood the test of time. I don't think
I'll change it right now.
Back to my original point. When one tests the return value of a Declared
Function, one can often gain information that may prompt one to check
GetLastError or LastDllError. When one declares a DLL Function as Sub, one
may lose that capability.
--
Lyle
(for e-mail refer to
http://ffdba.com/contacts.htm)