Hi all,
I'm Creating a wrapper dll for my favorite Windows API functions. Normally when windows API calls fail, Nothing happens and you don't know why and this frustrates me. Although you can use their return value to determine If it was successful.
My code (one example)
vb.net Code:
Public Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr Dim result As IntPtr = Declarations.SetParent(hWndChild, hWndNewParent) If result = IntPtr.Zero Then Dim ex As New System.ComponentModel.Win32Exception(Runtime.InteropServices.Marshal.GetLastWin32Error) throw ex End If End Function
My problem is that when I create a new exception to be thrown I can't set the stack trace or other necessary information. I need to set this because when I just throw the exception the debugger will go to the line that threw the exception and Not the actual call.
Any ideas ?
EDIT: It seems like the only way is to create a custom exception. I don't want to do that since I like the Win32 exception.




Reply With Quote