shellexecute function returning the 42 value

11,980 views
Skip to first unread message

jparada

unread,
Dec 21, 2010, 11:48:55 PM12/21/10
to Harbour Users
Hi,

Continuing the theme of avoiding the msdos window, what I did was the
following:

from minigui library, I just copy the c language function
shellexecute, and insert in my prg for testing:

This is the content of the function:
********************************************
#pragma begindump

#define _WIN32_IE 0x0500
#define HB_OS_WIN_32_USED
#define _WIN32_WINNT 0x0400
#include <shlobj.h>

#include <windows.h>
#include <commctrl.h>
#include "hbapi.h"
#include "hbvm.h"
#include "hbstack.h"
#include "hbapiitm.h"
#include "winreg.h"
#include "tchar.h"

HB_FUNC( SHELLEXECUTE )
{
hb_retnl( (LONG) ShellExecute( (HWND) hb_parnl(1),ISNIL(2) ? NULL :
(LPCSTR) hb_parc(2),(LPCSTR) hb_parc(3),ISNIL(4) ? NULL : (LPCSTR)
hb_parc(4),ISNIL(5) ? NULL : (LPCSTR) hb_parc(5),hb_parni(6) ) ) ;
}

#pragma enddump
********************************************

And I run the function like this:

wait shellexecute(0, "open", "sello.bat" )

And this works perfectly, I mean, it runs correctly my bat file and
hides the msdos window .... but the function returns 42 value, I have
searched about why returns the value 42 and I have not found anything
that can help me understand.

How can I get a "real" value, that let me know, for example, if the
process was completed successfully.

Even I do not even know if this function can work in Windows XP or
lower, I'm testing with Windows Vista.

I appreciate any help please.

Thank you very much

Best Regards,
Javier

Klas Engwall

unread,
Dec 22, 2010, 6:02:04 PM12/22/10
to harbou...@googlegroups.com
Javier,

[...]

> And I run the function like this:
>
> wait shellexecute(0, "open", "sello.bat" )
>
> And this works perfectly, I mean, it runs correctly my bat file and
> hides the msdos window .... but the function returns 42 value, I have
> searched about why returns the value 42 and I have not found anything
> that can help me understand.
>
> How can I get a "real" value, that let me know, for example, if the
> process was completed successfully.

According to <http://support.microsoft.com/kb/238245> a return value of
33 or above is the instance handle of the application that was called
while return values of 32 or below indicate an error. A list of possible
error codes is included in the kb document.

Regards,
Klas

jparada

unread,
Dec 23, 2010, 6:42:31 PM12/23/10
to Harbour Users
Hi Klas,

Thanks for answering.

And thanks for your answer, I had already seen the list of errors, but
I wanted to know what means the return value 42, because I was
confused at some sites indicated that return value and an error in the
execution of the process.

But now it has become clearer.

Thank you very much

Best Regards,
Javier


yclin

unread,
Jul 14, 2011, 3:03:20 AM7/14/11
to harbou...@googlegroups.com
Hi ~Jparada

Did you find out what the meaning about value 42 ?

Klas Engwall

unread,
Jul 14, 2011, 7:49:30 AM7/14/11
to harbou...@googlegroups.com
Hi yclin,

> Did you find out what the meaning about value 42 ?

Did you read my reply in the message before the one you responded to? It
means nothing, it is just a handle to the process.

Regards,
Klas

Reply all
Reply to author
Forward
0 new messages