]>
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"
28 #define INCL_DOSPROCESS
29 #define INCL_DOSERRORS
49 // this message is sent when the process we're waiting for terminates
50 #define wxWM_PROC_TERMINATED (WM_USER + 10000)
56 // structure describing the process we're being waiting for
62 cout
<< "Closing thread: " << endl
;
63 DosExit(EXIT_PROCESS
, 0);
66 HWND hWnd
; // window to send wxWM_PROC_TERMINATED to [not used]
67 RESULTCODES vResultCodes
;
69 ULONG ulExitCode
; // the exit code of the process
70 bool bState
; // set to FALSE when the process finishes
73 static ULONG
wxExecuteThread(
80 cout
<< "Executing thread: " << endl
;
82 ulRc
= ::DosWaitChild( DCWA_PROCESSTREE
86 ,pData
->vResultCodes
.codeTerminate
// process PID to look at
90 wxLogLastError("DosWaitChild");
96 // window procedure of a hidden window which is created just to receive
97 // the notification message when a process exits
98 MRESULT APIENTRY
wxExecuteWindowCbk(
105 if (ulMessage
== wxWM_PROC_TERMINATED
)
107 wxExecuteData
* pData
= (wxExecuteData
*)lParam
;
111 pData
->pHandler
->OnTerminate( (int)pData
->vResultCodes
.codeTerminate
112 ,(int)pData
->vResultCodes
.codeResult
118 // we're executing synchronously, tell the waiting thread
119 // that the process finished
124 // asynchronous execution - we should do the clean up
127 ::WinDestroyWindow(hWnd
); // we don't need it any more
132 extern wxChar wxPanelClassName
[];
135 const wxString
& rCommand
137 , wxProcess
* pHandler
140 if (rCommand
.IsEmpty())
142 cout
<< "empty command in wxExecute." << endl
;
146 // create the process
147 UCHAR vLoadError
[CCHMAXPATH
] = {0};
148 RESULTCODES vResultCodes
= {0};
158 ulExecFlag
= EXEC_SYNC
;
160 ulExecFlag
= EXEC_ASYNCRESULT
;
162 rc
= ::DosExecPgm( (PCHAR
)vLoadError
168 ,(PSZ
)rCommand
.c_str()
172 wxLogSysError(_("Execution of command '%s' failed with error: %ul"), rCommand
.c_str(), rc
);
175 cout
<< "Executing: " << rCommand
.c_str() << endl
;
177 wxExecuteData
* pData
= new wxExecuteData
;
179 pData
->vResultCodes
= vResultCodes
;
180 pData
->hWnd
= NULLHANDLE
;
181 pData
->bState
= bSync
;
184 wxASSERT_MSG(!pHandler
, wxT("wxProcess param ignored for sync execution"));
185 pData
->pHandler
= NULL
;
189 // may be NULL or not
190 pData
->pHandler
= pHandler
;
193 rc
= ::DosCreateThread( &vTID
194 ,(PFNTHREAD
)&wxExecuteThread
196 ,CREATE_READY
|STACK_SPARSE
201 wxLogLastError("CreateThread in wxExecute");
204 // the process still started up successfully...
205 return vResultCodes
.codeTerminate
;
210 // warning: don't exit your app unless you actively
211 // kill and cleanup you child processes
212 // Maybe detach the process here???
213 // If cmd.exe need to pass DETACH to detach the process here
214 return vResultCodes
.codeTerminate
;
217 // waiting until command executed
218 ::DosWaitThread(&vTID
, DCWW_WAIT
);
220 ULONG ulExitCode
= pData
->vResultCodes
.codeResult
;
223 // return the exit code
224 return (long)ulExitCode
;
230 , wxProcess
* pHandler
235 while (*ppArgv
!= NULL
)
237 sCommand
<< *ppArgv
++ << ' ';
239 sCommand
.RemoveLast();
240 return wxExecute( sCommand
246 bool wxGetFullHostName(
254 unsigned long ulLevel
= 0;
255 unsigned char* zBuffer
;
256 unsigned long ulBuffer
;
257 unsigned long* pulTotalAvail
;
259 NetBios32GetInfo( (const unsigned char*)zServer
260 ,(const unsigned char*)zComputer
266 strncpy(zBuf
, zComputer
, nMaxSize
);
267 zBuf
[nMaxSize
] = _T('\0');
269 strcpy(zBuf
, "noname");
271 return *zBuf
? TRUE
: FALSE
;