FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour app crash on ShellExecute()
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
app crash on ShellExecute()
Posted: Thu Jan 05, 2012 07:21 PM
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 (fw): Select all Collapse
//----------------------------------------------------------------------------
METHOD OpenFile() Class Referrings
   LOCAL cFile := temp_name( ALLTRIM( ::oDocsTbl:ImageType ) )
   LOCAL oWnd, lCreated

   //MemoWrit( cFile, ::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.
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: app crash on ShellExecute()
Posted: Thu Jan 05, 2012 07:48 PM

I had many problems with ShellExecute. I do now use Winexec with no problems.
Best regards,
Otto

Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: app crash on ShellExecute()
Posted: Thu Jan 05, 2012 07:56 PM

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.

Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
Re: app crash on ShellExecute()
Posted: Fri Jan 06, 2012 09:29 AM
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 (fw): Select all Collapse
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
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: app crash on ShellExecute()
Posted: Fri Jan 06, 2012 11:38 AM
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 (fw): Select all Collapse
WinExec( "START " + cDocument )


EMG
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: app crash on ShellExecute()
Posted: Fri Jan 06, 2012 04:30 PM

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.

Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
Re: app crash on ShellExecute()
Posted: Fri Jan 06, 2012 04:36 PM

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

http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: app crash on ShellExecute()
Posted: Fri Jan 06, 2012 04:52 PM
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
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: app crash on ShellExecute()
Posted: Fri Jan 06, 2012 06:56 PM
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.
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: app crash on ShellExecute()
Posted: Sat Jan 07, 2012 12:42 PM

Dear Reinaldo,

Have you tried

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

Kind Regards,

Frances



Fivewin for xHarbour v18.07

xHarbour v1.2.3.x

BCC 7.3 + PellesC8 ( Resource Compiler only)

ADS 10.1 / MariaDB

Crystal Reports 8.5/9.23 DE

xMate v1.15
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: app crash on ShellExecute()
Posted: Fri Jan 31, 2020 03:58 PM
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 (fw): Select all Collapse
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

Continue the discussion