]>
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
133 extern wxChar wxPanelClassName
[];
136 const wxString
& rCommand
138 , wxProcess
* pHandler
141 if (rCommand
.IsEmpty())
143 // cout << "empty command in wxExecute." << endl;
147 // create the process
148 UCHAR vLoadError
[CCHMAXPATH
] = {0};
149 RESULTCODES vResultCodes
= {0};
159 ulExecFlag
= EXEC_SYNC
;
161 ulExecFlag
= EXEC_ASYNCRESULT
;
163 rc
= ::DosExecPgm( (PCHAR
)vLoadError
169 ,(PSZ
)rCommand
.c_str()
173 wxLogSysError(_("Execution of command '%s' failed with error: %ul"), rCommand
.c_str(), rc
);
176 // cout << "Executing: " << rCommand.c_str() << endl;
178 wxExecuteData
* pData
= new wxExecuteData
;
180 pData
->vResultCodes
= vResultCodes
;
181 pData
->hWnd
= NULLHANDLE
;
182 pData
->bState
= bSync
;
185 wxASSERT_MSG(!pHandler
, wxT("wxProcess param ignored for sync execution"));
186 pData
->pHandler
= NULL
;
190 // may be NULL or not
191 pData
->pHandler
= pHandler
;
194 rc
= ::DosCreateThread( &vTID
195 ,(PFNTHREAD
)&wxExecuteThread
197 ,CREATE_READY
|STACK_SPARSE
202 wxLogLastError("CreateThread in wxExecute");
205 // the process still started up successfully...
206 return vResultCodes
.codeTerminate
;
211 // warning: don't exit your app unless you actively
212 // kill and cleanup you child processes
213 // Maybe detach the process here???
214 // If cmd.exe need to pass DETACH to detach the process here
215 return vResultCodes
.codeTerminate
;
218 // waiting until command executed
219 ::DosWaitThread(&vTID
, DCWW_WAIT
);
221 ULONG ulExitCode
= pData
->vResultCodes
.codeResult
;
224 // return the exit code
225 return (long)ulExitCode
;
231 , wxProcess
* pHandler
236 while (*ppArgv
!= NULL
)
238 sCommand
<< *ppArgv
++ << ' ';
240 sCommand
.RemoveLast();
241 return wxExecute( sCommand
247 bool wxGetFullHostName(
255 unsigned long ulLevel
= 0;
256 unsigned char* zBuffer
= NULL
;
257 unsigned long ulBuffer
= 256;
258 unsigned long* pulTotalAvail
= NULL
;
260 NetBios32GetInfo( (const unsigned char*)zServer
261 ,(const unsigned char*)zComputer
267 strncpy(zBuf
, zComputer
, nMaxSize
);
268 zBuf
[nMaxSize
] = _T('\0');
270 strcpy(zBuf
, "noname");
272 return *zBuf
? TRUE
: FALSE
;