When calling API's or other external functions it is only possible to get thrown errors using "GetLastError". I made the following function for this:
I have two questions to "simplify" my code usage:Code:Public Sub ThrowError() Dim ex As New System.ComponentModel.Win32Exception(Runtime.InteropServices.Marshal.GetLastWin32Error()) If ex.NativeErrorCode <> 0 Then Throw ex End Sub
1. How can I make the debugger point to where the "ThrowError" is called, instead of highlighting the "Throw ex" line. I can pass the location to this Function, but a Messagebox is not everything...
2. How can I make the "ThrowError" check get called whenever an API is used? For example, duplicating all API's and adding the call to ThrowError in the end is kind of lengthy:
Code:Private Class API Public Declare Function SetCursor Lib "user32" (ByVal hCursor As IntPtr) As IntPtr End Class Public Function SetCursor(ByVal hCursor As IntPtr) As IntPtr SetCursor = API.SetCursor(hCursor) ThrowError() End Function




Reply With Quote