<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Vidalia: win32.cpp Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.3 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_b47abd1aad201a152869566145babb61.html">src</a> » <a class="el" href="dir_3459d97d61361c9d41d467fba45f9c61.html">common</a> </div> </div> <div class="contents"> <h1>win32.cpp</h1><a href="win32_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment">** This file is part of Vidalia, and is subject to the license terms in the</span> <a name="l00003"></a>00003 <span class="comment">** LICENSE file, found in the top level directory of this distribution. If you</span> <a name="l00004"></a>00004 <span class="comment">** did not receive the LICENSE file with this file, you may obtain it from the</span> <a name="l00005"></a>00005 <span class="comment">** Vidalia source package distributed by the Vidalia Project at</span> <a name="l00006"></a>00006 <span class="comment">** http://www.vidalia-project.net/. No part of Vidalia, including this file,</span> <a name="l00007"></a>00007 <span class="comment">** may be copied, modified, propagated, or distributed except according to the</span> <a name="l00008"></a>00008 <span class="comment">** terms described in the LICENSE file.</span> <a name="l00009"></a>00009 <span class="comment">*/</span> <a name="l00010"></a>00010 <a name="l00011"></a>00011 <span class="comment">/*</span> <a name="l00012"></a>00012 <span class="comment">** \file win32.cpp</span> <a name="l00013"></a>00013 <span class="comment">** \version $Id: win32.cpp 4294 2010-05-18 03:58:45Z edmanm $ </span> <a name="l00014"></a>00014 <span class="comment">** \brief Win32-specific functions</span> <a name="l00015"></a>00015 <span class="comment">*/</span> <a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="preprocessor">#include "<a class="code" href="win32_8h.html">win32.h</a>"</span> <a name="l00018"></a>00018 <a name="l00019"></a>00019 <span class="preprocessor">#include <QDir></span> <a name="l00020"></a>00020 <span class="preprocessor">#include <QLibrary></span> <a name="l00021"></a>00021 <span class="preprocessor">#include <QtDebug></span> <a name="l00022"></a>00022 <a name="l00023"></a>00023 <span class="preprocessor">#include <tlhelp32.h></span> <a name="l00024"></a>00024 <span class="preprocessor">#include <shlobj.h></span> <a name="l00025"></a>00025 <a name="l00026"></a>00026 <span class="preprocessor">#if defined(UNICODE)</span> <a name="l00027"></a>00027 <span class="preprocessor"></span><span class="comment">/* Force the ascii verisons of these functions, so we can run on Win98. We</span> <a name="l00028"></a>00028 <span class="comment"> * don't pass any Unicode strings to these functions anyway. */</span> <a name="l00029"></a>00029 <span class="preprocessor">#undef PROCESSENTRY32</span> <a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#undef LPPROCESSENTRY32</span> <a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#undef Process32First</span> <a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#undef Process32Next</span> <a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00034"></a>00034 <span class="preprocessor"></span> <a name="l00035"></a>00035 <span class="comment">/* Load the tool help functions dynamically, since they don't exist on</span> <a name="l00036"></a>00036 <span class="comment"> * Windows NT 4.0 */</span> <a name="l00037"></a><a class="code" href="win32_8cpp.html#a43fbaed6900331036121cbf10ea89dcd">00037</a> <span class="keyword">typedef</span> HANDLE (WINAPI *<a class="code" href="win32_8cpp.html#a43fbaed6900331036121cbf10ea89dcd">CreateToolhelp32Snapshot_fn</a>)(DWORD, DWORD); <a name="l00038"></a><a class="code" href="win32_8cpp.html#a38b498b5a3717ce0ac288cfdfe516cd8">00038</a> <span class="keyword">typedef</span> BOOL (WINAPI *<a class="code" href="win32_8cpp.html#a38b498b5a3717ce0ac288cfdfe516cd8">Process32First_fn</a>)(HANDLE, LPPROCESSENTRY32); <a name="l00039"></a><a class="code" href="win32_8cpp.html#a0237d0fa6142bf28ce472f1969019008">00039</a> <span class="keyword">typedef</span> BOOL (WINAPI *<a class="code" href="win32_8cpp.html#a0237d0fa6142bf28ce472f1969019008">Process32Next_fn</a>)(HANDLE, LPPROCESSENTRY32); <a name="l00040"></a>00040 <a name="l00041"></a>00041 <span class="comment"></span> <a name="l00042"></a>00042 <span class="comment">/** Finds the location of the "special" Windows folder using the given CSIDL</span> <a name="l00043"></a>00043 <span class="comment"> * value. If the folder cannot be found, the given default path is used. */</span> <a name="l00044"></a>00044 QString <a name="l00045"></a><a class="code" href="win32_8cpp.html#adbac000f7429d20239fdd7c406de085b">00045</a> <a class="code" href="win32_8cpp.html#adbac000f7429d20239fdd7c406de085b">win32_get_folder_location</a>(<span class="keywordtype">int</span> folder, QString defaultPath) <a name="l00046"></a>00046 { <a name="l00047"></a>00047 TCHAR path[MAX_PATH+1]; <a name="l00048"></a>00048 LPITEMIDLIST idl; <a name="l00049"></a>00049 IMalloc *m; <a name="l00050"></a>00050 HRESULT result; <a name="l00051"></a>00051 <a name="l00052"></a>00052 <span class="comment">/* XXX: It would probably be a good idea to replace this function with simple</span> <a name="l00053"></a>00053 <span class="comment"> * calls to QDesktopServices::storageLocation(). Note that it returns the</span> <a name="l00054"></a>00054 <span class="comment"> * "Local Settings" application data directory though, so our installers</span> <a name="l00055"></a>00055 <span class="comment"> * would need to be updated as well.</span> <a name="l00056"></a>00056 <span class="comment"> */</span> <a name="l00057"></a>00057 <a name="l00058"></a>00058 <span class="comment">/* Find the location of %PROGRAMFILES% */</span> <a name="l00059"></a>00059 <span class="keywordflow">if</span> (SUCCEEDED(SHGetSpecialFolderLocation(NULL, folder, &idl))) { <a name="l00060"></a>00060 <span class="comment">/* Get the path from the IDL */</span> <a name="l00061"></a>00061 result = SHGetPathFromIDList(idl, path); <a name="l00062"></a>00062 SHGetMalloc(&m); <a name="l00063"></a>00063 <span class="keywordflow">if</span> (m) { <a name="l00064"></a>00064 m->Release(); <a name="l00065"></a>00065 } <a name="l00066"></a>00066 <span class="keywordflow">if</span> (SUCCEEDED(result)) { <a name="l00067"></a>00067 <span class="preprocessor">#if defined(UNICODE)</span> <a name="l00068"></a>00068 <span class="preprocessor"></span> <span class="keywordflow">return</span> QString::fromUtf16(static_cast<const ushort *>(path)); <a name="l00069"></a>00069 <span class="preprocessor">#else</span> <a name="l00070"></a>00070 <span class="preprocessor"></span> <span class="keywordflow">return</span> QString::fromLocal8Bit(static_cast<const char *>(path)); <a name="l00071"></a>00071 <span class="preprocessor">#endif</span> <a name="l00072"></a>00072 <span class="preprocessor"></span> } <a name="l00073"></a>00073 } <a name="l00074"></a>00074 <span class="keywordflow">return</span> defaultPath; <a name="l00075"></a>00075 } <a name="l00076"></a>00076 <span class="comment"></span> <a name="l00077"></a>00077 <span class="comment">/** Gets the location of the user's %PROGRAMFILES% folder. */</span> <a name="l00078"></a>00078 QString <a name="l00079"></a><a class="code" href="win32_8h.html#a5ef88e21c0f27849306e01326118f477">00079</a> <a class="code" href="win32_8cpp.html#a5ef88e21c0f27849306e01326118f477">win32_program_files_folder</a>() <a name="l00080"></a>00080 { <a name="l00081"></a>00081 <span class="keywordflow">return</span> <a class="code" href="win32_8cpp.html#adbac000f7429d20239fdd7c406de085b">win32_get_folder_location</a>( <a name="l00082"></a>00082 CSIDL_PROGRAM_FILES, QDir::rootPath() + <span class="stringliteral">"\\Program Files"</span>); <a name="l00083"></a>00083 } <a name="l00084"></a>00084 <span class="comment"></span> <a name="l00085"></a>00085 <span class="comment">/** Gets the location of the user's %APPDATA% folder. */</span> <a name="l00086"></a>00086 QString <a name="l00087"></a><a class="code" href="win32_8h.html#a3fe83170889be9d4f04e047a7809fd19">00087</a> <a class="code" href="win32_8cpp.html#a3fe83170889be9d4f04e047a7809fd19">win32_app_data_folder</a>() <a name="l00088"></a>00088 { <a name="l00089"></a>00089 <span class="keywordflow">return</span> <a class="code" href="win32_8cpp.html#adbac000f7429d20239fdd7c406de085b">win32_get_folder_location</a>( <a name="l00090"></a>00090 CSIDL_APPDATA, QDir::homePath() + <span class="stringliteral">"\\Application Data"</span>); <a name="l00091"></a>00091 } <a name="l00092"></a>00092 <span class="comment"></span> <a name="l00093"></a>00093 <span class="comment">/** Returns the value in keyName at keyLocation. </span> <a name="l00094"></a>00094 <span class="comment"> * Returns an empty QString if the keyName doesn't exist */</span> <a name="l00095"></a>00095 QString <a name="l00096"></a><a class="code" href="win32_8h.html#aaaa6bffe7e3d6b50806dd415f14c1553">00096</a> <a class="code" href="win32_8cpp.html#aaaa6bffe7e3d6b50806dd415f14c1553">win32_registry_get_key_value</a>(QString keyLocation, QString keyName) <a name="l00097"></a>00097 { <a name="l00098"></a>00098 HKEY key; <a name="l00099"></a>00099 <span class="keywordtype">char</span> data[255] = {0}; <a name="l00100"></a>00100 DWORD size = <span class="keyword">sizeof</span>(data); <a name="l00101"></a>00101 <a name="l00102"></a>00102 <span class="comment">/* Open the key for reading (opens new key if it doesn't exist) */</span> <a name="l00103"></a>00103 <span class="keywordflow">if</span> (RegOpenKeyExA(HKEY_CURRENT_USER, <a name="l00104"></a>00104 qPrintable(keyLocation), <a name="l00105"></a>00105 0L, KEY_READ, &key) == ERROR_SUCCESS) { <a name="l00106"></a>00106 <a name="l00107"></a>00107 <span class="comment">/* Key exists, so read the value into data */</span> <a name="l00108"></a>00108 RegQueryValueExA(key, qPrintable(keyName), <a name="l00109"></a>00109 NULL, NULL, (LPBYTE)data, &size); <a name="l00110"></a>00110 } <a name="l00111"></a>00111 <a name="l00112"></a>00112 <span class="comment">/* Close anything that was opened */</span> <a name="l00113"></a>00113 RegCloseKey(key); <a name="l00114"></a>00114 <a name="l00115"></a>00115 <span class="keywordflow">return</span> QString(data); <a name="l00116"></a>00116 } <a name="l00117"></a>00117 <span class="comment"></span> <a name="l00118"></a>00118 <span class="comment">/** Creates and/or sets the key to the specified value */</span> <a name="l00119"></a>00119 <span class="keywordtype">void</span> <a name="l00120"></a><a class="code" href="win32_8h.html#a58ee5814c8dee82025bb2ae5c154240d">00120</a> <a class="code" href="win32_8cpp.html#a58ee5814c8dee82025bb2ae5c154240d">win32_registry_set_key_value</a>(QString keyLocation, QString keyName, QString keyValue) <a name="l00121"></a>00121 { <a name="l00122"></a>00122 HKEY key; <a name="l00123"></a>00123 <a name="l00124"></a>00124 <span class="comment">/* Open the key for writing (opens new key if it doesn't exist */</span> <a name="l00125"></a>00125 <span class="keywordflow">if</span> (RegOpenKeyExA(HKEY_CURRENT_USER, <a name="l00126"></a>00126 qPrintable(keyLocation), <a name="l00127"></a>00127 0, KEY_WRITE, &key) != ERROR_SUCCESS) { <a name="l00128"></a>00128 <a name="l00129"></a>00129 <span class="comment">/* Key didn't exist, so write the newly opened key */</span> <a name="l00130"></a>00130 RegCreateKeyExA(HKEY_CURRENT_USER, <a name="l00131"></a>00131 qPrintable(keyLocation), <a name="l00132"></a>00132 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, <a name="l00133"></a>00133 &key, NULL); <a name="l00134"></a>00134 } <a name="l00135"></a>00135 <a name="l00136"></a>00136 <span class="comment">/* Save the value in the key */</span> <a name="l00137"></a>00137 RegSetValueExA(key, qPrintable(keyName), 0, REG_SZ, <a name="l00138"></a>00138 (BYTE *)qPrintable(keyValue), <a name="l00139"></a>00139 (DWORD)keyValue.length() + 1); <span class="comment">// include null terminator</span> <a name="l00140"></a>00140 <a name="l00141"></a>00141 <span class="comment">/* Close the key */</span> <a name="l00142"></a>00142 RegCloseKey(key); <a name="l00143"></a>00143 } <a name="l00144"></a>00144 <span class="comment"></span> <a name="l00145"></a>00145 <span class="comment">/** Removes the key from the registry if it exists */</span> <a name="l00146"></a>00146 <span class="keywordtype">void</span> <a name="l00147"></a><a class="code" href="win32_8h.html#a165375275dccaad4b2f38a09d38b98ad">00147</a> <a class="code" href="win32_8cpp.html#a165375275dccaad4b2f38a09d38b98ad">win32_registry_remove_key</a>(QString keyLocation, QString keyName) <a name="l00148"></a>00148 { <a name="l00149"></a>00149 HKEY key; <a name="l00150"></a>00150 <a name="l00151"></a>00151 <span class="comment">/* Open the key for writing (opens new key if it doesn't exist */</span> <a name="l00152"></a>00152 <span class="keywordflow">if</span> (RegOpenKeyExA(HKEY_CURRENT_USER, <a name="l00153"></a>00153 qPrintable(keyLocation), <a name="l00154"></a>00154 0, KEY_SET_VALUE, &key) == ERROR_SUCCESS) { <a name="l00155"></a>00155 <a name="l00156"></a>00156 <span class="comment">/* Key exists so delete it */</span> <a name="l00157"></a>00157 RegDeleteValueA(key, qPrintable(keyName)); <a name="l00158"></a>00158 } <a name="l00159"></a>00159 <a name="l00160"></a>00160 <span class="comment">/* Close anything that was opened */</span> <a name="l00161"></a>00161 RegCloseKey(key); <a name="l00162"></a>00162 } <a name="l00163"></a>00163 <span class="comment"></span> <a name="l00164"></a>00164 <span class="comment">/**</span> <a name="l00165"></a>00165 <span class="comment"> * Callback for EnumThreadWindows which sends the WM_QUIT message</span> <a name="l00166"></a>00166 <span class="comment"> */</span> <a name="l00167"></a>00167 BOOL CALLBACK <a name="l00168"></a><a class="code" href="win32_8cpp.html#ad4a80e9382bab2913f50cd3ba9027014">00168</a> <a class="code" href="win32_8cpp.html#ad4a80e9382bab2913f50cd3ba9027014">quitWindowCallback</a>(HWND hwnd, LPARAM targetPID) <a name="l00169"></a>00169 { <a name="l00170"></a>00170 DWORD hwndPID = 0; <a name="l00171"></a>00171 <a name="l00172"></a>00172 <span class="comment">/* If the process ID for hwnd matches the target PID, post</span> <a name="l00173"></a>00173 <span class="comment"> WM_QUIT to the window */</span> <a name="l00174"></a>00174 GetWindowThreadProcessId(hwnd, &hwndPID); <a name="l00175"></a>00175 <span class="keywordflow">if</span> (hwndPID == (DWORD)targetPID) <a name="l00176"></a>00176 PostMessage(hwnd, WM_QUIT, 0, (LPARAM)NULL); <a name="l00177"></a>00177 <span class="keywordflow">return</span> TRUE; <a name="l00178"></a>00178 } <a name="l00179"></a>00179 <span class="comment"></span> <a name="l00180"></a>00180 <span class="comment">/**</span> <a name="l00181"></a>00181 <span class="comment"> * Close process with the specified PID. Sends WM_QUIT to all</span> <a name="l00182"></a>00182 <span class="comment"> * top-level windows.</span> <a name="l00183"></a>00183 <span class="comment"> */</span> <a name="l00184"></a>00184 <span class="keywordtype">void</span> <a name="l00185"></a><a class="code" href="win32_8cpp.html#a203f0db370783cdc1e654046cc98ef51">00185</a> <a class="code" href="win32_8cpp.html#a203f0db370783cdc1e654046cc98ef51">win32_end_process_by_pid</a>(DWORD pid) <a name="l00186"></a>00186 { <a name="l00187"></a>00187 <span class="comment">/* Send WM_QUIT to all windows */</span> <a name="l00188"></a>00188 EnumWindows(&<a class="code" href="win32_8cpp.html#ad4a80e9382bab2913f50cd3ba9027014">quitWindowCallback</a>, (LPARAM)pid); <a name="l00189"></a>00189 <span class="comment">/* At this point we could kill the main thread, but how do we find</span> <a name="l00190"></a>00190 <span class="comment"> the ID of the main thread? We can find the ID of all threads</span> <a name="l00191"></a>00191 <span class="comment"> but killing them all seems to cause a problem for Firefox */</span> <a name="l00192"></a>00192 <span class="comment">//PostThreadMessage(thread.th32ThreadID, WM_CLOSE, 0, (LPARAM)NULL);</span> <a name="l00193"></a>00193 } <a name="l00194"></a>00194 <span class="comment"></span> <a name="l00195"></a>00195 <span class="comment">/**</span> <a name="l00196"></a>00196 <span class="comment"> * Close all processes started from the specified filename. Sends</span> <a name="l00197"></a>00197 <span class="comment"> * WM_QUIT to all top-level windows. Filename should be given in</span> <a name="l00198"></a>00198 <span class="comment"> * lowercase, and comparison is case insensitive. Note: the MSDN</span> <a name="l00199"></a>00199 <span class="comment"> * documentation for WM_QUIT states that the message should not be</span> <a name="l00200"></a>00200 <span class="comment"> * sent by PostMessage(). However, sending WM_CLOSE leaves Firefox</span> <a name="l00201"></a>00201 <span class="comment"> * running, whereas WM_QUIT seems to work.</span> <a name="l00202"></a>00202 <span class="comment"> */</span> <a name="l00203"></a>00203 <span class="keywordtype">void</span> <a name="l00204"></a><a class="code" href="win32_8h.html#a546813bc9cee9692be35c062e1502bca">00204</a> <a class="code" href="win32_8cpp.html#a546813bc9cee9692be35c062e1502bca">win32_end_process_by_filename</a>(QString filename) <a name="l00205"></a>00205 { <a name="l00206"></a>00206 <span class="comment">/* Get list of running processes */</span> <a name="l00207"></a>00207 QHash<qint64, QString> procList = <a class="code" href="win32_8cpp.html#a8af39b060612b54ccf604ccbf9c4c415">win32_process_list</a>(); <a name="l00208"></a>00208 <a name="l00209"></a>00209 <span class="comment">/* On old versions of Windows win32_process_list() will return</span> <a name="l00210"></a>00210 <span class="comment"> an empty list. In this case, just keep Vidalia open */</span> <a name="l00211"></a>00211 <span class="keywordflow">if</span> (procList.isEmpty()) { <a name="l00212"></a>00212 <span class="keywordflow">return</span>; <a name="l00213"></a>00213 } <a name="l00214"></a>00214 <a name="l00215"></a>00215 <span class="comment">/* Loop over all processes */</span> <a name="l00216"></a>00216 QHashIterator<qint64, QString> <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>(procList); <a name="l00217"></a>00217 <span class="keywordflow">while</span> (i.hasNext()) { <a name="l00218"></a>00218 i.next(); <a name="l00219"></a>00219 <span class="keywordflow">if</span> (i.value().toLower() == filename) { <a name="l00220"></a>00220 <span class="comment">/* Kill this process */</span> <a name="l00221"></a>00221 <a class="code" href="win32_8cpp.html#a203f0db370783cdc1e654046cc98ef51">win32_end_process_by_pid</a>((DWORD)i.key()); <a name="l00222"></a>00222 } <a name="l00223"></a>00223 } <a name="l00224"></a>00224 } <a name="l00225"></a>00225 <span class="comment"></span> <a name="l00226"></a>00226 <span class="comment">/** Returns a list of all currently active processes, including their pid</span> <a name="l00227"></a>00227 <span class="comment"> * and exe filename. */</span> <a name="l00228"></a>00228 QHash<qint64, QString> <a name="l00229"></a><a class="code" href="win32_8h.html#a8af39b060612b54ccf604ccbf9c4c415">00229</a> <a class="code" href="win32_8cpp.html#a8af39b060612b54ccf604ccbf9c4c415">win32_process_list</a>() <a name="l00230"></a>00230 { <a name="l00231"></a>00231 QHash<qint64, QString> procList; <a name="l00232"></a>00232 <a class="code" href="win32_8cpp.html#a43fbaed6900331036121cbf10ea89dcd">CreateToolhelp32Snapshot_fn</a> pCreateToolhelp32Snapshot; <a name="l00233"></a>00233 <a class="code" href="win32_8cpp.html#a38b498b5a3717ce0ac288cfdfe516cd8">Process32First_fn</a> pProcess32First; <a name="l00234"></a>00234 <a class="code" href="win32_8cpp.html#a0237d0fa6142bf28ce472f1969019008">Process32Next_fn</a> pProcess32Next; <a name="l00235"></a>00235 HANDLE hSnapshot; <a name="l00236"></a>00236 PROCESSENTRY32 proc; <a name="l00237"></a>00237 QString exeFile; <a name="l00238"></a>00238 qint64 pid; <a name="l00239"></a>00239 <a name="l00240"></a>00240 <span class="comment">/* Load the tool help functions */</span> <a name="l00241"></a>00241 pCreateToolhelp32Snapshot = <a name="l00242"></a>00242 (<a class="code" href="win32_8cpp.html#a43fbaed6900331036121cbf10ea89dcd">CreateToolhelp32Snapshot_fn</a>)QLibrary::resolve(<span class="stringliteral">"kernel32"</span>, <span class="stringliteral">"CreateToolhelp32Snapshot"</span>); <a name="l00243"></a>00243 pProcess32First = (<a class="code" href="win32_8cpp.html#a38b498b5a3717ce0ac288cfdfe516cd8">Process32First_fn</a>)QLibrary::resolve(<span class="stringliteral">"kernel32"</span>, <span class="stringliteral">"Process32First"</span>); <a name="l00244"></a>00244 pProcess32Next = (<a class="code" href="win32_8cpp.html#a0237d0fa6142bf28ce472f1969019008">Process32Next_fn</a>)QLibrary::resolve(<span class="stringliteral">"kernel32"</span>, <span class="stringliteral">"Process32Next"</span>); <a name="l00245"></a>00245 <a name="l00246"></a>00246 <span class="keywordflow">if</span> (!pCreateToolhelp32Snapshot || !pProcess32First || !pProcess32Next) { <a name="l00247"></a>00247 qWarning(<span class="stringliteral">"Unable to load tool help functions. Running process information "</span> <a name="l00248"></a>00248 <span class="stringliteral">"will be unavailable."</span>); <a name="l00249"></a>00249 <span class="keywordflow">return</span> QHash<qint64, QString>(); <a name="l00250"></a>00250 } <a name="l00251"></a>00251 <a name="l00252"></a>00252 <span class="comment">/* Create a snapshot of all active processes */</span> <a name="l00253"></a>00253 hSnapshot = pCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); <a name="l00254"></a>00254 <span class="keywordflow">if</span> (hSnapshot != INVALID_HANDLE_VALUE) { <a name="l00255"></a>00255 proc.dwSize = <span class="keyword">sizeof</span>(PROCESSENTRY32); <a name="l00256"></a>00256 <a name="l00257"></a>00257 <span class="comment">/* Iterate through all the processes in the snapshot */</span> <a name="l00258"></a>00258 <span class="keywordflow">if</span> (pProcess32First(hSnapshot, &proc)) { <a name="l00259"></a>00259 <span class="keywordflow">do</span> { <a name="l00260"></a>00260 <span class="comment">/* Extract the PID and exe filename from the process record */</span> <a name="l00261"></a>00261 pid = (qint64)proc.th32ProcessID; <a name="l00262"></a>00262 exeFile = QString::fromAscii((<span class="keyword">const</span> <span class="keywordtype">char</span> *)proc.szExeFile); <a name="l00263"></a>00263 <a name="l00264"></a>00264 <span class="comment">/* Add this process to our list */</span> <a name="l00265"></a>00265 procList.insert(pid, exeFile); <a name="l00266"></a>00266 } <span class="keywordflow">while</span> (pProcess32Next(hSnapshot, &proc)); <a name="l00267"></a>00267 } <a name="l00268"></a>00268 CloseHandle(hSnapshot); <a name="l00269"></a>00269 } <a name="l00270"></a>00270 <span class="keywordflow">return</span> procList; <a name="l00271"></a>00271 } <a name="l00272"></a>00272 </pre></div></div> <hr class="footer"/><address style="text-align: right;"><small>Generated on Mon Aug 30 22:58:55 2010 for Vidalia by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address> </body> </html>