]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/utilsexc.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     Various utilities 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  24 #include "wx/process.h" 
  26 #include "wx/os2/private.h" 
  52 // this message is sent when the process we're waiting for terminates 
  53 #define wxWM_PROC_TERMINATED (WM_USER + 10000) 
  59 // structure describing the process we're being waiting for 
  65 //         cout << "Closing thread: " << endl; 
  66         DosExit(EXIT_PROCESS
, 0); 
  69     HWND         hWnd
;          // window to send wxWM_PROC_TERMINATED to [not used] 
  70     RESULTCODES  vResultCodes
; 
  72     ULONG        ulExitCode
;    // the exit code of the process 
  73     bool         bState
;        // set to false when the process finishes 
  76 static ULONG 
wxExecuteThread(wxExecuteData
* pData
) 
  81 //     cout << "Executing thread: " << endl; 
  83     ulRc 
= ::DosWaitChild( DCWA_PROCESSTREE
 
  87                           ,pData
->vResultCodes
.codeTerminate 
// process PID to look at 
  91         wxLogLastError(wxT("DosWaitChild")); 
  97 // window procedure of a hidden window which is created just to receive 
  98 // the notification message when a process exits 
  99 MRESULT APIENTRY 
wxExecuteWindowCbk( HWND   hWnd
, 
 101                                      MPARAM 
WXUNUSED(wParam
), 
 104     if (ulMessage 
== wxWM_PROC_TERMINATED
) 
 106         wxExecuteData
*              pData 
= (wxExecuteData 
*)lParam
; 
 110             pData
->pHandler
->OnTerminate( (int)pData
->vResultCodes
.codeTerminate
 
 111                                          ,(int)pData
->vResultCodes
.codeResult
 
 117             // we're executing synchronously, tell the waiting thread 
 118             // that the process finished 
 123             // asynchronous execution - we should do the clean up 
 126         ::WinDestroyWindow(hWnd
);    // we don't need it any more 
 131 long wxExecute( const wxString
& rCommand
, 
 135     if (rCommand
.empty()) 
 137 //         cout << "empty command in wxExecute." << endl; 
 141     // create the process 
 142     UCHAR                           vLoadError
[CCHMAXPATH
] = {0}; 
 143     RESULTCODES                     vResultCodes 
= {0}; 
 150     if (flags 
& wxEXEC_SYNC
) 
 151         ulExecFlag 
= EXEC_SYNC
; 
 153         ulExecFlag 
= EXEC_ASYNCRESULT
; 
 155     rc 
= ::DosExecPgm( (PCHAR
)vLoadError
 
 161                       ,(PSZ
)rCommand
.c_str() 
 165         wxLogSysError(_("Execution of command '%s' failed with error: %ul"), rCommand
.c_str(), rc
); 
 168 //     cout << "Executing: " << rCommand.c_str() << endl; 
 170     wxExecuteData
*                  pData 
= new wxExecuteData
; 
 172     pData
->vResultCodes 
= vResultCodes
; 
 173     pData
->hWnd         
= NULLHANDLE
; 
 174     pData
->bState       
= (flags 
& wxEXEC_SYNC
) != 0; 
 175     if (flags 
& wxEXEC_SYNC
) 
 177         wxASSERT_MSG(!pHandler
, wxT("wxProcess param ignored for sync execution")); 
 178         pData
->pHandler 
= NULL
; 
 182         // may be NULL or not 
 183         pData
->pHandler 
= pHandler
; 
 186     rc 
= ::DosCreateThread( &vTID
 
 187                            ,(PFNTHREAD
)&wxExecuteThread
 
 189                            ,CREATE_READY
|STACK_SPARSE
 
 194         wxLogLastError(wxT("CreateThread in wxExecute")); 
 197         // the process still started up successfully... 
 198         return vResultCodes
.codeTerminate
; 
 200     if (!(flags 
& wxEXEC_SYNC
)) 
 203         // warning: don't exit your app unless you actively 
 204         // kill and cleanup you child processes 
 205         // Maybe detach the process here??? 
 206         // If cmd.exe need to pass DETACH to detach the process here 
 207         return vResultCodes
.codeTerminate
; 
 210     // waiting until command executed 
 211     ::DosWaitThread(&vTID
, DCWW_WAIT
); 
 213     ULONG ulExitCode 
= pData
->vResultCodes
.codeResult
; 
 216     // return the exit code 
 217     return (long)ulExitCode
; 
 223 , wxProcess
*                        pHandler
 
 228     while (*ppArgv 
!= NULL
) 
 230         wxString                    
sArg((wxChar
*)(*ppArgv
++)); 
 233         sCommand 
<< sArg
.c_str() << ' '; 
 235     sCommand
.RemoveLast(); 
 236     return wxExecute( sCommand
 
 242 bool wxGetFullHostName( wxChar
* zBuf
, 
 248     unsigned long                   ulLevel 
= 0; 
 249     unsigned char*                  zBuffer 
= NULL
; 
 250     unsigned long                   ulBuffer 
= 256; 
 251     unsigned long*                  pulTotalAvail 
= NULL
; 
 253     NetBios32GetInfo( (const unsigned char*)zServer
 
 254                      ,(const unsigned char*)zComputer
 
 260     strncpy(zBuf
, zComputer
, nMaxSize
); 
 261     zBuf
[nMaxSize
] = _T('\0'); 
 263     wxUnusedVar(nMaxSize
); 
 264     strcpy((char*)zBuf
, "noname"); 
 266     return *zBuf 
? true : false;