From: Peter Duniho on
Tony Johansson wrote:
> Hi!
>
> Does any of those Win32 API functions throw Exceptions that I can catch in
> my managed code or do they use the GetLastError which cause that I have to
> use the Marshal.GetLastWin32Error ?

No Win32 functions throw exceptions. For those functions that don't
return HRESULTs, you'll need to use GetLastWin32Error(). For those that
do return HRESULTs, you can use the PreserveSig field of the
DllImportAttribute, setting it to false to have the marshaler convert
HRESULT error codes to exceptions.

Pete
From: Tony Johansson on
"Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> skrev i meddelandet
news:ujP0gqA6KHA.4940(a)TK2MSFTNGP05.phx.gbl...
> Tony Johansson wrote:
>> Hi!
>>
>> Does any of those Win32 API functions throw Exceptions that I can catch
>> in my managed code or do they use the GetLastError which cause that I
>> have to use the Marshal.GetLastWin32Error ?
>
> No Win32 functions throw exceptions. For those functions that don't
> return HRESULTs, you'll need to use GetLastWin32Error(). For those that
> do return HRESULTs, you can use the PreserveSig field of the
> DllImportAttribute, setting it to false to have the marshaler convert
> HRESULT error codes to exceptions.
>
> Pete

You say
For those that do return HRESULTs, you can use the PreserveSig field of the
DllImportAttribute, setting it to false to have the marshaler convert
HRESULT error codes to exceptions.

Why is it not possible to use the the returned HRESULT ?

//Tony


From: Peter Duniho on
Tony Johansson wrote:
> [...]
> You say
> For those that do return HRESULTs, you can use the PreserveSig field of the
> DllImportAttribute, setting it to false to have the marshaler convert
> HRESULT error codes to exceptions.
>
> Why is it not possible to use the the returned HRESULT ?

What makes you think it's not? I only said you _can_ set the
PreserveSig field to false, not that you _must_.