~hikiko/nux/arb-srgba-shader

« back to all changes in this revision

Viewing changes to NuxCore/NProcess.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-01 19:25:37 UTC
  • Revision ID: neil.patel@canonical.com-20100901192537-mfz7rm6q262pewg6
Import and build NuxCore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "NKernel.h"
 
2
 
 
3
NAMESPACE_BEGIN
 
4
 
 
5
#ifdef _WIN32
 
6
//
 
7
// Launch a uniform resource locator (i.e. http://www.yahoo.com/finance).
 
8
// This is expected to return immediately as the URL is launched by another
 
9
// task.
 
10
//
 
11
void inlLaunchURL( const TCHAR* URL, const TCHAR* Parms, NString* Error )
 
12
{
 
13
    nuxDebugMsg( TEXT("LaunchURL %s %s"), URL, Parms?Parms:TEXT("") );
 
14
    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));
 
15
    if(Error)
 
16
        *Error = (int)Code <= 32 ? TEXT("UrlFailed") : TEXT("");
 
17
}
 
18
 
 
19
//
 
20
// Creates a new process and its primary thread. The new process runs the
 
21
// specified executable file in the security context of the calling process.
 
22
//
 
23
void *inlCreateProc( const TCHAR* URL, const TCHAR* Parms )
 
24
{
 
25
    nuxDebugMsg(  TEXT("CreateProc %s %s"), URL, Parms );
 
26
 
 
27
    TCHAR CommandLine[1024];
 
28
    Snprintf( CommandLine, 1024, 1024-1, TEXT("%s %s"), URL, Parms );
 
29
 
 
30
    PROCESS_INFORMATION ProcInfo;
 
31
    SECURITY_ATTRIBUTES Attr;
 
32
    Attr.nLength = sizeof(SECURITY_ATTRIBUTES);
 
33
    Attr.lpSecurityDescriptor = NULL;
 
34
    Attr.bInheritHandle = TRUE;
 
35
 
 
36
    STARTUPINFO StartupInfo = { sizeof(STARTUPINFO), NULL, NULL, NULL,
 
37
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
 
38
        NULL, NULL, NULL, NULL, SW_HIDE, NULL, NULL,
 
39
        NULL, NULL, NULL };
 
40
    if( !CreateProcess( NULL, CommandLine, &Attr, &Attr, TRUE, DETACHED_PROCESS | REALTIME_PRIORITY_CLASS,
 
41
        NULL, NULL, &StartupInfo, &ProcInfo ) )
 
42
        return NULL;
 
43
 
 
44
    return (void*)ProcInfo.hProcess;
 
45
}
 
46
 
 
47
//
 
48
// Retrieves the termination status of the specified process.
 
49
//
 
50
BOOL inlGetProcReturnCode( void* ProcHandle, INT* ReturnCode )
 
51
{
 
52
    return GetExitCodeProcess( (HANDLE)ProcHandle, (DWORD*)ReturnCode ) && *((DWORD*)ReturnCode) != STILL_ACTIVE;
 
53
}
 
54
 
 
55
 
 
56
INL_IMPLEMENT_GLOBAL_OBJECT(NProcess);
 
57
 
 
58
void NProcess::Constructor()
 
59
{
 
60
    m_ProcessID = GetCurrentProcessId();
 
61
    m_ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, m_ProcessID);
 
62
 
 
63
    m_MainThreadID = GetCurrentThreadId();
 
64
    m_MainThreadHandle = OpenThread(THREAD_ALL_ACCESS, FALSE, m_MainThreadID);
 
65
}
 
66
 
 
67
void NProcess::Destructor()
 
68
{
 
69
    CloseHandle(m_MainThreadHandle);
 
70
    CloseHandle(m_ProcessHandle);
 
71
}
 
72
 
 
73
HANDLE NProcess::GetProcessHandle()
 
74
{
 
75
    return m_ProcessHandle;
 
76
}
 
77
 
 
78
DWORD NProcess::GetProcessID()
 
79
{
 
80
    return m_ProcessID;
 
81
}
 
82
 
 
83
HANDLE NProcess::GetMainThreadHandle()
 
84
{
 
85
    return m_MainThreadHandle;
 
86
}
 
87
 
 
88
DWORD NProcess::GetMainThreadID()
 
89
{
 
90
    return m_MainThreadID;
 
91
}
 
92
 
 
93
HANDLE NProcess::GetCurrentThreadHandle()
 
94
{
 
95
    DWORD ThreadID = GetCurrentThreadId();
 
96
    return OpenThread(THREAD_ALL_ACCESS, FALSE, ThreadID);
 
97
}
 
98
 
 
99
DWORD NProcess::GetCurrentThreadID()
 
100
{
 
101
    return GetCurrentThreadId();
 
102
}
 
103
 
 
104
#endif
 
105
 
 
106
NAMESPACE_END
 
107