]>
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"
50 // this message is sent when the process we're waiting for terminates
51 #define wxWM_PROC_TERMINATED (WM_USER + 10000)
57 // structure describing the process we're being waiting for
63 // cout << "Closing thread: " << endl;
64 DosExit(EXIT_PROCESS
, 0);
67 HWND hWnd
; // window to send wxWM_PROC_TERMINATED to [not used]
68 RESULTCODES vResultCodes
;
70 ULONG ulExitCode
; // the exit code of the process
71 bool bState
; // set to FALSE when the process finishes
74 static ULONG
wxExecuteThread(
81 // cout << "Executing thread: " << endl;
83 ulRc
= ::DosWaitChild( DCWA_PROCESSTREE
87 ,pData
->vResultCodes
.codeTerminate
// process PID to look at
91 wxLogLastError("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(
106 if (ulMessage
== wxWM_PROC_TERMINATED
)
108 wxExecuteData
* pData
= (wxExecuteData
*)lParam
;
112 pData
->pHandler
->OnTerminate( (int)pData
->vResultCodes
.codeTerminate
113 ,(int)pData
->vResultCodes
.codeResult
119 // we're executing synchronously, tell the waiting thread
120 // that the process finished
125 // asynchronous execution - we should do the clean up
128 ::WinDestroyWindow(hWnd
); // we don't need it any more
134 const wxString
& rCommand
136 , wxProcess
* pHandler
139 if (rCommand
.IsEmpty())
141 // cout << "empty command in wxExecute." << endl;
145 // create the process
146 UCHAR vLoadError
[CCHMAXPATH
] = {0};
147 RESULTCODES vResultCodes
= {0};
157 ulExecFlag
= EXEC_SYNC
;
159 ulExecFlag
= EXEC_ASYNCRESULT
;
161 rc
= ::DosExecPgm( (PCHAR
)vLoadError
167 ,(PSZ
)rCommand
.c_str()
171 wxLogSysError(_("Execution of command '%s' failed with error: %ul"), rCommand
.c_str(), rc
);
174 // cout << "Executing: " << rCommand.c_str() << endl;
176 wxExecuteData
* pData
= new wxExecuteData
;
178 pData
->vResultCodes
= vResultCodes
;
179 pData
->hWnd
= NULLHANDLE
;
180 pData
->bState
= bSync
;
183 wxASSERT_MSG(!pHandler
, wxT("wxProcess param ignored for sync execution"));
184 pData
->pHandler
= NULL
;
188 // may be NULL or not
189 pData
->pHandler
= pHandler
;
192 rc
= ::DosCreateThread( &vTID
193 ,(PFNTHREAD
)&wxExecuteThread
195 ,CREATE_READY
|STACK_SPARSE
200 wxLogLastError("CreateThread in wxExecute");
203 // the process still started up successfully...
204 return vResultCodes
.codeTerminate
;
209 // warning: don't exit your app unless you actively
210 // kill and cleanup you child processes
211 // Maybe detach the process here???
212 // If cmd.exe need to pass DETACH to detach the process here
213 return vResultCodes
.codeTerminate
;
216 // waiting until command executed
217 ::DosWaitThread(&vTID
, DCWW_WAIT
);
219 ULONG ulExitCode
= pData
->vResultCodes
.codeResult
;
222 // return the exit code
223 return (long)ulExitCode
;
229 , wxProcess
* pHandler
234 while (*ppArgv
!= NULL
)
236 sCommand
<< *ppArgv
++ << ' ';
238 sCommand
.RemoveLast();
239 return wxExecute( sCommand
245 bool wxGetFullHostName(
253 unsigned long ulLevel
= 0;
254 unsigned char* zBuffer
= NULL
;
255 unsigned long ulBuffer
= 256;
256 unsigned long* pulTotalAvail
= NULL
;
258 NetBios32GetInfo( (const unsigned char*)zServer
259 ,(const unsigned char*)zComputer
265 strncpy(zBuf
, zComputer
, nMaxSize
);
266 zBuf
[nMaxSize
] = _T('\0');
268 strcpy(zBuf
, "noname");
270 return *zBuf
? TRUE
: FALSE
;