2
* Copyright 2010 Inalogic Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jaytaoko@inalogic.com>
30
// Launch a uniform resource locator (i.e. http://www.yahoo.com/finance).
31
// This is expected to return immediately as the URL is launched by another
34
void inlLaunchURL ( const TCHAR *URL, const TCHAR *Parms, NString *Error )
36
nuxDebugMsg ( TEXT ("LaunchURL %s %s"), URL, Parms ? Parms : TEXT ("") );
37
HINSTANCE Code = CALL_OS_TCHAR_FUNCTION (ShellExecuteW (NULL, TEXT ("open"), URL, Parms ? Parms : TEXT (""), TEXT (""), SW_SHOWNORMAL), ShellExecuteA (NULL, "open", TCHAR_TO_ANSI (URL), Parms ? TCHAR_TO_ANSI (Parms) : "", "", SW_SHOWNORMAL) );
40
*Error = (int) Code <= 32 ? TEXT ("UrlFailed") : TEXT ("");
44
// Creates a new process and its primary thread. The new process runs the
45
// specified executable file in the security context of the calling process.
47
void *inlCreateProc ( const TCHAR *URL, const TCHAR *Parms )
49
nuxDebugMsg ( TEXT ("CreateProc %s %s"), URL, Parms );
51
TCHAR CommandLine[1024];
52
Snprintf ( CommandLine, 1024, 1024 - 1, TEXT ("%s %s"), URL, Parms );
54
PROCESS_INFORMATION ProcInfo;
55
SECURITY_ATTRIBUTES Attr;
56
Attr.nLength = sizeof (SECURITY_ATTRIBUTES);
57
Attr.lpSecurityDescriptor = NULL;
58
Attr.bInheritHandle = TRUE;
60
STARTUPINFO StartupInfo = { sizeof (STARTUPINFO), NULL, NULL, NULL,
61
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
62
NULL, NULL, NULL, NULL, SW_HIDE, NULL, NULL,
66
if ( !CreateProcess ( NULL, CommandLine, &Attr, &Attr, TRUE, DETACHED_PROCESS | REALTIME_PRIORITY_CLASS,
67
NULL, NULL, &StartupInfo, &ProcInfo ) )
70
return (void *) ProcInfo.hProcess;
74
// Retrieves the termination status of the specified process.
76
BOOL inlGetProcReturnCode ( void *ProcHandle, INT *ReturnCode )
78
return GetExitCodeProcess ( (HANDLE) ProcHandle, (DWORD *) ReturnCode ) && * ( (DWORD *) ReturnCode) != STILL_ACTIVE;
82
NUX_IMPLEMENT_GLOBAL_OBJECT (NProcess);
84
void NProcess::Constructor()
86
m_ProcessID = GetCurrentProcessId();
87
m_ProcessHandle = OpenProcess (PROCESS_ALL_ACCESS, FALSE, m_ProcessID);
89
m_MainThreadID = GetCurrentThreadId();
90
m_MainThreadHandle = OpenThread (THREAD_ALL_ACCESS, FALSE, m_MainThreadID);
93
void NProcess::Destructor()
95
CloseHandle (m_MainThreadHandle);
96
CloseHandle (m_ProcessHandle);
99
HANDLE NProcess::GetProcessHandle()
101
return m_ProcessHandle;
104
DWORD NProcess::GetProcessID()
109
HANDLE NProcess::GetMainThreadHandle()
111
return m_MainThreadHandle;
114
DWORD NProcess::GetMainThreadID()
116
return m_MainThreadID;
119
HANDLE NProcess::GetCurrentThreadHandle()
121
DWORD ThreadID = GetCurrentThreadId();
122
return OpenThread (THREAD_ALL_ACCESS, FALSE, ThreadID);
125
DWORD NProcess::GetCurrentThreadID()
127
return GetCurrentThreadId();