]>
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"
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(
83 // cout << "Executing thread: " << endl;
85 ulRc
= ::DosWaitChild( DCWA_PROCESSTREE
89 ,pData
->vResultCodes
.codeTerminate
// process PID to look at
93 wxLogLastError("DosWaitChild");
99 // window procedure of a hidden window which is created just to receive
100 // the notification message when a process exits
101 MRESULT APIENTRY
wxExecuteWindowCbk(
108 if (ulMessage
== wxWM_PROC_TERMINATED
)
110 wxExecuteData
* pData
= (wxExecuteData
*)lParam
;
114 pData
->pHandler
->OnTerminate( (int)pData
->vResultCodes
.codeTerminate
115 ,(int)pData
->vResultCodes
.codeResult
121 // we're executing synchronously, tell the waiting thread
122 // that the process finished
127 // asynchronous execution - we should do the clean up
130 ::WinDestroyWindow(hWnd
); // we don't need it any more
135 extern wxChar wxPanelClassName
[];
138 const wxString
& rCommand
140 , wxProcess
* pHandler
143 if (rCommand
.IsEmpty())
145 // cout << "empty command in wxExecute." << endl;
149 // create the process
150 UCHAR vLoadError
[CCHMAXPATH
] = {0};
151 RESULTCODES vResultCodes
= {0};
161 ulExecFlag
= EXEC_SYNC
;
163 ulExecFlag
= EXEC_ASYNCRESULT
;
165 rc
= ::DosExecPgm( (PCHAR
)vLoadError
171 ,(PSZ
)rCommand
.c_str()
175 wxLogSysError(_("Execution of command '%s' failed with error: %ul"), rCommand
.c_str(), rc
);
178 // cout << "Executing: " << rCommand.c_str() << endl;
180 wxExecuteData
* pData
= new wxExecuteData
;
182 pData
->vResultCodes
= vResultCodes
;
183 pData
->hWnd
= NULLHANDLE
;
184 pData
->bState
= bSync
;
187 wxASSERT_MSG(!pHandler
, wxT("wxProcess param ignored for sync execution"));
188 pData
->pHandler
= NULL
;
192 // may be NULL or not
193 pData
->pHandler
= pHandler
;
196 rc
= ::DosCreateThread( &vTID
197 ,(PFNTHREAD
)&wxExecuteThread
199 ,CREATE_READY
|STACK_SPARSE
204 wxLogLastError("CreateThread in wxExecute");
207 // the process still started up successfully...
208 return vResultCodes
.codeTerminate
;
213 // warning: don't exit your app unless you actively
214 // kill and cleanup you child processes
215 // Maybe detach the process here???
216 // If cmd.exe need to pass DETACH to detach the process here
217 return vResultCodes
.codeTerminate
;
220 // waiting until command executed
221 ::DosWaitThread(&vTID
, DCWW_WAIT
);
223 ULONG ulExitCode
= pData
->vResultCodes
.codeResult
;
226 // return the exit code
227 return (long)ulExitCode
;
233 , wxProcess
* pHandler
238 while (*ppArgv
!= NULL
)
240 sCommand
<< *ppArgv
++ << ' ';
242 sCommand
.RemoveLast();
243 return wxExecute( sCommand
249 bool wxGetFullHostName(
257 unsigned long ulLevel
= 0;
258 unsigned char* zBuffer
= NULL
;
259 unsigned long ulBuffer
= 256;
260 unsigned long* pulTotalAvail
= NULL
;
262 NetBios32GetInfo( (const unsigned char*)zServer
263 ,(const unsigned char*)zComputer
269 strncpy(zBuf
, zComputer
, nMaxSize
);
270 zBuf
[nMaxSize
] = _T('\0');
272 strcpy(zBuf
, "noname");
274 return *zBuf
? TRUE
: FALSE
;