]>
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"
47 // already defined via nerror.h in app.h so undef them
74 // this message is sent when the process we're waiting for terminates
75 #define wxWM_PROC_TERMINATED (WM_USER + 10000)
81 // structure describing the process we're being waiting for
87 // cout << "Closing thread: " << endl;
88 DosExit(EXIT_PROCESS
, 0);
91 HWND hWnd
; // window to send wxWM_PROC_TERMINATED to [not used]
92 RESULTCODES vResultCodes
;
94 ULONG ulExitCode
; // the exit code of the process
95 bool bState
; // set to FALSE when the process finishes
98 static ULONG
wxExecuteThread(
105 // cout << "Executing thread: " << endl;
107 ulRc
= ::DosWaitChild( DCWA_PROCESSTREE
109 ,&pData
->vResultCodes
111 ,pData
->vResultCodes
.codeTerminate
// process PID to look at
113 if (ulRc
!= NO_ERROR
)
115 wxLogLastError("DosWaitChild");
121 // window procedure of a hidden window which is created just to receive
122 // the notification message when a process exits
123 MRESULT APIENTRY
wxExecuteWindowCbk(
130 if (ulMessage
== wxWM_PROC_TERMINATED
)
132 wxExecuteData
* pData
= (wxExecuteData
*)lParam
;
136 pData
->pHandler
->OnTerminate( (int)pData
->vResultCodes
.codeTerminate
137 ,(int)pData
->vResultCodes
.codeResult
143 // we're executing synchronously, tell the waiting thread
144 // that the process finished
149 // asynchronous execution - we should do the clean up
152 ::WinDestroyWindow(hWnd
); // we don't need it any more
157 extern wxChar wxPanelClassName
[];
160 const wxString
& rCommand
162 , wxProcess
* pHandler
165 if (rCommand
.IsEmpty())
167 // cout << "empty command in wxExecute." << endl;
171 // create the process
172 UCHAR vLoadError
[CCHMAXPATH
] = {0};
173 RESULTCODES vResultCodes
= {0};
183 ulExecFlag
= EXEC_SYNC
;
185 ulExecFlag
= EXEC_ASYNCRESULT
;
187 rc
= ::DosExecPgm( (PCHAR
)vLoadError
193 ,(PSZ
)rCommand
.c_str()
197 wxLogSysError(_("Execution of command '%s' failed with error: %ul"), rCommand
.c_str(), rc
);
200 // cout << "Executing: " << rCommand.c_str() << endl;
202 wxExecuteData
* pData
= new wxExecuteData
;
204 pData
->vResultCodes
= vResultCodes
;
205 pData
->hWnd
= NULLHANDLE
;
206 pData
->bState
= bSync
;
209 wxASSERT_MSG(!pHandler
, wxT("wxProcess param ignored for sync execution"));
210 pData
->pHandler
= NULL
;
214 // may be NULL or not
215 pData
->pHandler
= pHandler
;
218 rc
= ::DosCreateThread( &vTID
219 ,(PFNTHREAD
)&wxExecuteThread
221 ,CREATE_READY
|STACK_SPARSE
226 wxLogLastError("CreateThread in wxExecute");
229 // the process still started up successfully...
230 return vResultCodes
.codeTerminate
;
235 // warning: don't exit your app unless you actively
236 // kill and cleanup you child processes
237 // Maybe detach the process here???
238 // If cmd.exe need to pass DETACH to detach the process here
239 return vResultCodes
.codeTerminate
;
242 // waiting until command executed
243 ::DosWaitThread(&vTID
, DCWW_WAIT
);
245 ULONG ulExitCode
= pData
->vResultCodes
.codeResult
;
248 // return the exit code
249 return (long)ulExitCode
;
255 , wxProcess
* pHandler
260 while (*ppArgv
!= NULL
)
262 sCommand
<< *ppArgv
++ << ' ';
264 sCommand
.RemoveLast();
265 return wxExecute( sCommand
271 bool wxGetFullHostName(
279 unsigned long ulLevel
= 0;
280 unsigned char* zBuffer
= NULL
;
281 unsigned long ulBuffer
= 256;
282 unsigned long* pulTotalAvail
= NULL
;
284 NetBios32GetInfo( (const unsigned char*)zServer
285 ,(const unsigned char*)zComputer
291 strncpy(zBuf
, zComputer
, nMaxSize
);
292 zBuf
[nMaxSize
] = _T('\0');
294 strcpy(zBuf
, "noname");
296 return *zBuf
? TRUE
: FALSE
;