Get Error Message When Calling A Win API In PowerBuilder
External Function declaration
1 2 3 4 |
//[External Function declaration] Function Long GetLastError() Library "kernel32" Alias For "GetLastError" Function Long FormatMessage (Long dwFlags ,Ref Any lpSource , Long dwMessageId , Long dwLanguageId , Ref String lpBuffer , Long nSize , Long Arguments) Library "kernel32" Alias For "FormatMessageA" Function Long ShellExecuteA( Long hwnd, String lpOperation, String lpFile, String lpParameters, String lpDirectory, Integer nShowCmd ) Library "SHELL32" |
PowerScript Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
//PowerScript String ls_Null Long ll_rc String ls_err_str Long ll_last_error Any temp Constant Long FORMAT_MESSAGE_FROM_SYSTEM = 4096 SetNull(ls_Null) // try to execute a non-existent filename. ll_rc = ShellExecuteA( Handle( This ), "open", & "MyPage.xyz", ls_Null, ls_Null, 1) If ll_rc > 1 Then temp = 0 ll_last_error = GetLastError() ls_err_str = Fill(Char(0),255) FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, temp, ll_last_error, 0, Ref ls_err_str, 255, 0) MessageBox("error", ls_err_str) End If |
Good Luck!
Subscribe
Login
0 Comments