]>
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 license
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"
45 // this message is sent when the process we're waiting for terminates
46 #define wxWM_PROC_TERMINATED (WM_USER + 10000)
52 // structure describing the process we're being waiting for
58 cout
<< "Closing thread: " << endl
;
59 DosExit(EXIT_PROCESS
, 0);
62 HWND hWnd
; // window to send wxWM_PROC_TERMINATED to [not used]
63 RESULTCODES vResultCodes
;
65 ULONG ulExitCode
; // the exit code of the process
66 bool bState
; // set to FALSE when the process finishes
69 static ULONG
wxExecuteThread(
76 cout
<< "Executing thread: " << endl
;
78 ulRc
= ::DosWaitChild( DCWA_PROCESSTREE
82 ,pData
->vResultCodes
.codeTerminate
// process PID to look at
86 wxLogLastError("DosWaitChild");
92 // window procedure of a hidden window which is created just to receive
93 // the notification message when a process exits
94 MRESULT APIENTRY
wxExecuteWindowCbk(
101 if (ulMessage
== wxWM_PROC_TERMINATED
)
103 wxExecuteData
* pData
= (wxExecuteData
*)lParam
;
107 pData
->pHandler
->OnTerminate( (int)pData
->vResultCodes
.codeTerminate
108 ,(int)pData
->vResultCodes
.codeResult
114 // we're executing synchronously, tell the waiting thread
115 // that the process finished
120 // asynchronous execution - we should do the clean up
123 ::WinDestroyWindow(hWnd
); // we don't need it any more
128 extern wxChar wxPanelClassName
[];
131 const wxString
& rCommand
133 , wxProcess
* pHandler
136 if (rCommand
.IsEmpty())
138 cout
<< "empty command in wxExecute." << endl
;
142 // create the process
143 UCHAR vLoadError
[CCHMAXPATH
] = {0};
144 RESULTCODES vResultCodes
= {0};
154 ulExecFlag
= EXEC_SYNC
;
156 ulExecFlag
= EXEC_ASYNCRESULT
;
158 rc
= ::DosExecPgm( (PCHAR
)vLoadError
164 ,(PSZ
)rCommand
.c_str()
168 wxLogSysError(_("Execution of command '%s' failed with error: %ul"), rCommand
.c_str(), rc
);
171 cout
<< "Executing: " << rCommand
.c_str() << endl
;
173 wxExecuteData
* pData
= new wxExecuteData
;
175 pData
->vResultCodes
= vResultCodes
;
176 pData
->hWnd
= NULLHANDLE
;
177 pData
->bState
= bSync
;
180 wxASSERT_MSG(!pHandler
, wxT("wxProcess param ignored for sync execution"));
181 pData
->pHandler
= NULL
;
185 // may be NULL or not
186 pData
->pHandler
= pHandler
;
189 rc
= ::DosCreateThread( &vTID
190 ,(PFNTHREAD
)&wxExecuteThread
192 ,CREATE_READY
|STACK_SPARSE
197 wxLogLastError("CreateThread in wxExecute");
200 // the process still started up successfully...
201 return vResultCodes
.codeTerminate
;
206 // warning: don't exit your app unless you actively
207 // kill and cleanup you child processes
208 // Maybe detach the process here???
209 // If cmd.exe need to pass DETACH to detach the process here
210 return vResultCodes
.codeTerminate
;
213 // waiting until command executed
214 ::DosWaitThread(&vTID
, DCWW_WAIT
);
216 ULONG ulExitCode
= pData
->vResultCodes
.codeResult
;
219 // return the exit code
220 return (long)ulExitCode
;
226 , wxProcess
* pHandler
231 while (*ppArgv
!= NULL
)
233 sCommand
<< *ppArgv
++ << ' ';
235 sCommand
.RemoveLast();
236 return wxExecute( sCommand
242 bool wxGetFullHostName(
250 unsigned long ulLevel
= 0;
251 unsigned char* zBuffer
;
252 unsigned long ulBuffer
;
253 unsigned long* pulTotalAvail
;
255 NetBios32GetInfo( (const unsigned char*)zServer
256 ,(const unsigned char*)zComputer
262 strncpy(zBuf
, zComputer
, nMaxSize
);
263 zBuf
[nMaxSize
] = _T('\0');
265 strcpy(zBuf
, "noname");
267 return *zBuf
? TRUE
: FALSE
;