From: Tony Johansson on
Hi!

Here is some text from Microsoft press(exam 70-536).

"Exceptions in unmanaged code are markedly different from those thrown in
managed code. In earlier COM days, you could use the GetLastError function
to get the last error that was raised. This approach won't work in a managed
application because the return value of GetLastError might not be the
correct one. Why ? because the GetLastError method can be set by either a
..NET framework object or the common language runtime(CLR) "

What does this last sentence actually mean here. It says "because the
GetLastError method can be set by either a .NET framework object or the
common language runtime(CLR) "

What is the difference between NET framework object or the common language
runtime(CLR) ?

//Tony


From: Tony Johansson on

"Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> skrev i meddelandet
news:eVAUS7e5KHA.4888(a)TK2MSFTNGP06.phx.gbl...
> Tony Johansson wrote:
>> Hi!
>>
>> Here is some text from Microsoft press(exam 70-536).
>>
>> "Exceptions in unmanaged code are markedly different from those thrown in
>> managed code. In earlier COM days, you could use the GetLastError
>> function to get the last error that was raised. This approach won't work
>> in a managed application because the return value of GetLastError might
>> not be the correct one. Why ? because the GetLastError method can be set
>> by either a ..NET framework object or the common language runtime(CLR) "
>>
>> What does this last sentence actually mean here. It says "because the
>> GetLastError method can be set by either a .NET framework object or the
>> common language runtime(CLR) "
>>
>> What is the difference between NET framework object or the common
>> language runtime(CLR) ?
>
> CLR is the thing that lets .NET Framework objects work. The framework
> objects are, of course, the objects themselves.
>
> Note that the [DllImport] attribute has the SetLastError field, which you
> can set to true for a p/invoke declaration. This allows you to call
> Marshal.GetLastWin32Error() and retrieve the actual error code set by
> SetLastError(), even if the CLR or some other .NET Framework object
> changes it before your own code gets control back.
>
> Pete

Hi!

So do you mean it's a good manner to use Marshal.GetLastWin32Error() after
each unmanaged call that could cause error ?

//Tony
Marshal.GetLastWin32Error()