ShellExecute function wrapper
- Posted by ryanj May 27, 2016
- 1641 views
Forked from Re: RedyCode 0.9.0 officially released!
I downloaded the latest version, unzipped it, and launched it.
I opened up a project, told it to run the program... and boom. All the windows closed.
Opening it up again didn't give me any hint as to what might have gone wrong.
Uh-oh. What OS are you using? Is there no ex.err anywhere?
I am beginning to suspect a rare problem with the ShellExecute() wrapper, but it's not something that i have been able to reproduce.
From https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx:
Return value
Type: HINSTANCE
If the function succeeds, it returns a value greater than 32. If the function fails, it returns an error value that indicates the cause of the failure. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. It is not a true HINSTANCE, however. It can be cast only to an int and compared to either 32 or the following error codes below.
What does that mean?
I have
xShellExecute = link_c_func(shell32, "ShellExecuteA", {C_HWND, C_POINTER, C_POINTER, C_POINTER, C_POINTER, C_INT}, C_HWND) public function ShellExecute(atom WinHwnd, sequence filename, sequence parameter, sequence verb = "", sequence workingdir = "") atom result,szapp,szpara,szaction,szdirectory szaction=allocate_string(verb) szapp=allocate_string(filename) szpara=allocate_string(parameter) szdirectory=allocate_string(workingdir) result=c_func(xShellExecute,{WinHwnd,szaction,szapp,szpara,szdirectory,SW_SHOWNORMAL}) free(szaction) free(szpara) free(szapp) if result > 32 then --If the function succeeds, it returns a value greater than 32. return 1 --success else return 0 --failure end if end function
Should it be changed to this? Or does it matter?
xShellExecute = link_c_func(shell32, "ShellExecuteA", {C_HWND, C_POINTER, C_POINTER, C_POINTER, C_POINTER, C_INT}, C_INT)