]>
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 licence
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};
154 if (flags
& wxEXEC_SYNC
)
155 ulExecFlag
= EXEC_SYNC
;
157 ulExecFlag
= EXEC_ASYNCRESULT
;
159 rc
= ::DosExecPgm( (PCHAR
)vLoadError
165 ,(PSZ
)rCommand
.c_str()
169 wxLogSysError(_("Execution of command '%s' failed with error: %ul"), rCommand
.c_str(), rc
);
172 // cout << "Executing: " << rCommand.c_str() << endl;
174 wxExecuteData
* pData
= new wxExecuteData
;
176 pData
->vResultCodes
= vResultCodes
;
177 pData
->hWnd
= NULLHANDLE
;
178 pData
->bState
= (flags
& wxEXEC_SYNC
) != 0;
179 if (flags
& wxEXEC_SYNC
)
181 wxASSERT_MSG(!pHandler
, wxT("wxProcess param ignored for sync execution"));
182 pData
->pHandler
= NULL
;
186 // may be NULL or not
187 pData
->pHandler
= pHandler
;
190 rc
= ::DosCreateThread( &vTID
191 ,(PFNTHREAD
)&wxExecuteThread
193 ,CREATE_READY
|STACK_SPARSE
198 wxLogLastError("CreateThread in wxExecute");
201 // the process still started up successfully...
202 return vResultCodes
.codeTerminate
;
204 if (!(flags
& wxEXEC_SYNC
))
207 // warning: don't exit your app unless you actively
208 // kill and cleanup you child processes
209 // Maybe detach the process here???
210 // If cmd.exe need to pass DETACH to detach the process here
211 return vResultCodes
.codeTerminate
;
214 // waiting until command executed
215 ::DosWaitThread(&vTID
, DCWW_WAIT
);
217 ULONG ulExitCode
= pData
->vResultCodes
.codeResult
;
220 // return the exit code
221 return (long)ulExitCode
;
227 , wxProcess
* pHandler
232 while (*ppArgv
!= NULL
)
234 wxString
sArg((wxChar
*)(*ppArgv
++));
237 sCommand
<< sArg
.c_str() << ' ';
239 sCommand
.RemoveLast();
240 return wxExecute( sCommand
246 bool wxGetFullHostName(
254 unsigned long ulLevel
= 0;
255 unsigned char* zBuffer
= NULL
;
256 unsigned long ulBuffer
= 256;
257 unsigned long* pulTotalAvail
= NULL
;
259 NetBios32GetInfo( (const unsigned char*)zServer
260 ,(const unsigned char*)zComputer
266 strncpy(zBuf
, zComputer
, nMaxSize
);
267 zBuf
[nMaxSize
] = _T('\0');
269 strcpy((char*)zBuf
, "noname");
271 return *zBuf
? TRUE
: FALSE
;