Page 1 of 1

app crash on ShellExecute()

Posted: Thu Jan 05, 2012 7:21 pm
by reinaldocrespo
Hi.

I'm getting an occasional gpf exception:

Problem signature:
Problem Event Name: APPCRASH
Application Name: PathLabs10.Exe
Application Version: 0.0.0.0
Application Timestamp: 00000000
Fault Module Name: StackHash_ff05
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 00000000
Exception Code: c000001d
Exception Offset: 04ae8155
OS Version: 6.1.7600.2.0.0.256.1
Locale ID: 1033
Additional Information 1: ff05
Additional Information 2: ff05f37046acef5185ebb7cab4cbfa4d
Additional Information 3: de26
Additional Information 4: de26bf487b3c10560592a1bede0ad9ce
It happens when executing the command ShellExecute() from the code below:

Code: Select all


//----------------------------------------------------------------------------
METHOD OpenFile() Class Referrings
   LOCAL cFile := temp_name( ALLTRIM( ::oDocsTbl:ImageType ) )
   LOCAL oWnd, lCreated

   //MemoWrit( cFile, ::oDocsTbl:Image )
   lCreated := (::oDocsTbl:cAlias)->( BLOBExport( ::oDocsTbl:FieldPos("Image"), cfile , BLOB_EXPORT_OVERWRITE ) )

   IF file( cFile ) .AND. lCreated

      DEFINE WINDOW oWnd FROM 0,0 TO -1, -1
      ACTIVATE WINDOW oWnd ON INIT ;
         ShellExecute( 0, "Open", cfile,,,1 )

      oWnd:End()

   ENDIF
      
RETURN NIL 
 
When the gpf occurs it does before executing oWnd:End() but cfile is opened and displayed just fine. Most times cfile is a pdf. Any ideas where to look?


Reinaldo.

Re: app crash on ShellExecute()

Posted: Thu Jan 05, 2012 7:48 pm
by Otto
I had many problems with ShellExecute. I do now use Winexec with no problems.
Best regards,
Otto

Re: app crash on ShellExecute()

Posted: Thu Jan 05, 2012 7:56 pm
by reinaldocrespo
Thank you very much.

Ok. I see. The problem I have is that I'm trying to open a document. It might be a .docx, or a .xls, or a .pdf, etc... WinExec() executes an app but it does not seem to open a document with it's associated app (if there is one). Right?


Reinaldo.

Re: app crash on ShellExecute()

Posted: Fri Jan 06, 2012 9:29 am
by Richard Chidiak
Reinaldo ,

For opening documents (pdf ..) or executing internet tasks i use this piece of code instead of shellexecute

works Ok for me,

Hth

Richard

Code: Select all

Function WebBrowser(cUrl,lvisible)
local oIE := CREATEOBJECT( "InternetExplorer.Application" )
IF LVISIBLE == nil
   lVisible := .t.
ENDIF
WITH OBJECT oIE
   :Visible   := LVISIBLE  
   :ToolBar   := .F.
   :StatusBar := .F.
   :MenuBar   := .F.
   :Invoke( "Navigate", cUrl )
END WITH
RETURN NIL
 

Re: app crash on ShellExecute()

Posted: Fri Jan 06, 2012 11:38 am
by Enrico Maria Giordano
reinaldocrespo wrote:The problem I have is that I'm trying to open a document. It might be a .docx, or a .xls, or a .pdf, etc... WinExec() executes an app but it does not seem to open a document with it's associated app (if there is one). Right?
Try

Code: Select all

WinExec( "START " + cDocument )
EMG

Re: app crash on ShellExecute()

Posted: Fri Jan 06, 2012 4:30 pm
by reinaldocrespo
Enrico;

I really like your solution for its simplicity. However, for some reason, it doesn't always work. I would think that perhaps the file association isn't set but that is not the case. If I type the filename manually on the command prompt the associated app will open the file -while from source code, sometimes nothing happens.

Richard's solution seems to work but it opens ie, which I'd like to avoid.


Reinaldo.

Re: app crash on ShellExecute()

Posted: Fri Jan 06, 2012 4:36 pm
by Richard Chidiak
Reinaldo

Opening ie is default behaviour that you can change

WebBrowser(cUrl,.f.) // does not show ie , i use it this way for all php i execute on my server, it goes silent

Richard

Re: app crash on ShellExecute()

Posted: Fri Jan 06, 2012 4:52 pm
by Enrico Maria Giordano
reinaldocrespo wrote:Enrico;

I really like your solution for its simplicity. However, for some reason, it doesn't always work. I would think that perhaps the file association isn't set but that is not the case. If I type the filename manually on the command prompt the associated app will open the file -while from source code, sometimes nothing happens.

Richard's solution seems to work but it opens ie, which I'd like to avoid.


Reinaldo.
Please note that if cDocument contains spaces you have to enclose it in quotes (just like you have to do on the console).

EMG

Re: app crash on ShellExecute()

Posted: Fri Jan 06, 2012 6:56 pm
by reinaldocrespo
Enrico;

There are no spaces. I don't use the quotes when I test from the console either. And yes... it does work well from the console:
start c:\users\admini~1\locals~1\temp\4872091.pdf
But from code, nothing happens:

WinExec( "START " + ALLTRIM( cFile ) )
where cfile contains: C:\Users\ADMINI~1\LOCALS~1\Temp\4872091.pdf

I appreciate your input and suggestions. I will continue testing with other files to see if I can debug this thing.



Reinaldo.

Re: app crash on ShellExecute()

Posted: Sat Jan 07, 2012 12:42 pm
by fraxzi
Dear Reinaldo,

Have you tried

WinExec( 'START "' + ALLTRIM( cFile )+'"' ) ?

Re: app crash on ShellExecute()

Posted: Fri Jan 31, 2020 3:58 pm
by Otto
Hello,
Thank you for this code.
I use it now to open my help system on the internet.
I inserted the line oIE := NIL . Otherwise, the code calling twice errored out.
Best regards
Otto

Code: Select all

Function WebBrowser(cUrl,lvisible)
    local oIE := CREATEOBJECT( "InternetExplorer.Application" )
    IF LVISIBLE == nil
       lVisible := .t.
    ENDIF
    WITH OBJECT oIE
       :Visible   := LVISIBLE  
       :ToolBar   := .F.
       :StatusBar := .F.
       :MenuBar   := .F.
       :Invoke( "Navigate", cUrl )
    END WITH
    
    
    oIE := NIL
    RETURN NIL