]>
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"
40 // this message is sent when the process we're waiting for terminates
41 #define wxWM_PROC_TERMINATED (WM_USER + 10000)
47 // structure describing the process we're being waiting for
53 DosExit(EXIT_PROCESS
, 0);
56 HWND hWnd
; // window to send wxWM_PROC_TERMINATED to [not used]
57 RESULTCODES vResultCodes
;
59 ULONG ulExitCode
; // the exit code of the process
60 bool bState
; // set to FALSE when the process finishes
63 static ULONG
wxExecuteThread(
70 ulRc
= ::DosWaitChild( DCWA_PROCESSTREE
74 ,pData
->vResultCodes
.codeTerminate
// process PID to look at
78 wxLogLastError("DosWaitChild");
83 // ::WinSendMsg(pData->hWnd, (ULONG)wxWM_PROC_TERMINATED, 0, (MPARAM)pData);
87 // Unlike windows where everything needs a window, console apps in OS/2
88 // need no windows so this is not ever used
89 MRESULT APIENTRY
wxExecuteWindowCbk(
96 if (ulMessage
== wxWM_PROC_TERMINATED
)
98 wxExecuteData
* pData
= (wxExecuteData
*)lParam
;
102 pData
->pHandler
->OnTerminate( (int)pData
->vResultCodes
.codeTerminate
103 ,(int)pData
->vResultCodes
.codeResult
109 // we're executing synchronously, tell the waiting thread
110 // that the process finished
115 // asynchronous execution - we should do the clean up
118 ::WinDestroyWindow(hWnd
); // we don't need it any more
123 extern wxChar wxPanelClassName
[];
126 const wxString
& rCommand
128 , wxProcess
* pHandler
131 wxCHECK_MSG(!!rCommand
, 0, wxT("empty command in wxExecute"));
133 // create the process
134 UCHAR vLoadError
[CCHMAXPATH
] = {0};
135 RESULTCODES vResultCodes
= {0};
145 ulExecFlag
= EXEC_SYNC
;
147 ulExecFlag
= EXEC_ASYNCRESULT
;
149 if (::DosExecPgm( (PCHAR
)vLoadError
158 wxLogSysError(_("Execution of command '%s' failed"), rCommand
.c_str());
162 // PM does not need non visible object windows to run console child processes
164 HWND hwnd = ::WinCreateWindow( HWND_DESKTOP
178 wxASSERT_MSG( hwnd, wxT("can't create a hidden window for wxExecute") );
179 pOldProc = ::WinSubclassWindow(hwnd, (PFNWP)&wxExecuteWindowCbk);
183 wxExecuteData
* pData
= new wxExecuteData
;
185 pData
->vResultCodes
= vResultCodes
;
186 pData
->hWnd
= NULLHANDLE
;
187 pData
->bState
= bSync
;
190 wxASSERT_MSG(!pHandler
, wxT("wxProcess param ignored for sync execution"));
191 pData
->pHandler
= NULL
;
195 // may be NULL or not
196 pData
->pHandler
= pHandler
;
199 rc
= ::DosCreateThread( &vTID
200 ,(PFNTHREAD
)&wxExecuteThread
202 ,CREATE_READY
|STACK_SPARSE
207 wxLogLastError("CreateThread in wxExecute");
209 // ::WinDestroyWindow(hwnd);
212 // the process still started up successfully...
213 return vResultCodes
.codeTerminate
;
217 // clean up will be done when the process terminates
220 return vResultCodes
.codeTerminate
;
222 ::DosWaitThread(&vTID
, DCWW_WAIT
);
224 ULONG ulExitCode
= pData
->vResultCodes
.codeResult
;
227 // return the exit code
228 return (long)ulExitCode
;
234 , wxProcess
* pHandler
239 while (*ppArgv
!= NULL
)
241 sCommand
<< *ppArgv
++ << ' ';
243 sCommand
.RemoveLast();
244 return wxExecute( sCommand
250 bool wxGetFullHostName(
258 unsigned short nLevel
= 0;
259 unsigned char* zBuffer
;
260 unsigned short nBuffer
;
261 unsigned short* pnTotalAvail
;
263 NetBios32GetInfo( (const unsigned char*)zServer
264 ,(const unsigned char*)zComputer
270 strncpy(zBuf
, zComputer
, nMaxSize
);
271 zBuf
[nMaxSize
] = _T('\0');
273 strcpy(zBuf
, "noname");
275 return *zBuf
? TRUE
: FALSE
;