Prev: Data type enforcement in DataGridView
Next: using a String Builder a actual parameter and LPTSTR as formal parameter in unmanaged code
From: Tony Johansson on 29 Apr 2010 12:52 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 ? //Tony
From: Jeff Johnson on 29 Apr 2010 13:46 "Tony Johansson" <johansson.andersson(a)telia.com> wrote in message news:OCIYRx75KHA.348(a)TK2MSFTNGP02.phx.gbl... > 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 ? Exceptions are managed, so no, unmanaged code will not throw exceptions. The closest you'll get is COMException, and that comes from the managed wrapper around the COM object.
From: Tom Shelton on 29 Apr 2010 14:58 On 2010-04-29, Tony Johansson <johansson.andersson(a)telia.com> 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 ? > > //Tony > > They will not directly throw an exception - but, I will often write code like this: int apiReturn = SomeApiFunction() if (apiReturn == API_FAILED) { throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error); } -- Tom Shelton
From: Tony Johansson on 29 Apr 2010 15:06 "Jeff Johnson" <i.get(a)enough.spam> skrev i meddelandet news:%23i%23MZP85KHA.5016(a)TK2MSFTNGP02.phx.gbl... > "Tony Johansson" <johansson.andersson(a)telia.com> wrote in message > news:OCIYRx75KHA.348(a)TK2MSFTNGP02.phx.gbl... > >> 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 ? > > Exceptions are managed, so no, unmanaged code will not throw exceptions. > The closest you'll get is COMException, and that comes from the managed > wrapper around the COM object. But you can have unmanaged code that throw exception for example C++ code. So I disagree with you when you say that Exceptions are managed. I have written a lot of C++ code and this code is unmanaged but I have used exception handling for error. //Tony
From: Jeff Johnson on 29 Apr 2010 15:26
"Tony Johansson" <johansson.andersson(a)telia.com> wrote in message news:OZsq9785KHA.5808(a)TK2MSFTNGP02.phx.gbl... >> Exceptions are managed, so no, unmanaged code will not throw exceptions. >> The closest you'll get is COMException, and that comes from the managed >> wrapper around the COM object. > > But you can have unmanaged code that throw exception for example C++ code. > So I disagree with you when you say that Exceptions are managed. > I have written a lot of C++ code and this code is unmanaged but I have > used exception handling for error. Your C++ code might thrown an "exception" but it does not throw an "Exception," i.e., a System.Exception. |