WINDOWS核心編程之進程(二)

大笑微笑生氣吐舌頭吐舌頭吐舌頭吐舌頭吐舌頭吐舌頭吐舌頭吐舌頭吐舌頭吐舌頭吐舌頭生氣微笑大笑


偷笑我愛北京天安門偷笑


偷笑天安門上太陽升偷笑


偷笑偉大領袖毛主席偷笑


偷笑指引我們向前進偷笑

偷笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑偷笑

<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=4>2004年7月14日&nbsp; 晚20:30</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=4></FONT></SPAN>&nbsp;</P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT color=#ff1493 size=4>1.進程的實例句柄</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=4><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">加載到進程地址空間的每個可執行文件或</SPAN><SPAN lang=EN>DLL</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件均被產生一個唯一的實例句柄,就是</SPAN><SPAN lang=EN>hinstExe</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">參數</SPAN><SPAN lang=EN>.</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有些這個參數的類型爲</SPAN><SPAN lang=EN>HMODULE</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">類型,</SPAN></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=4><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">注意</SPAN><SPAN lang=EN>:</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">這兩個類型是完全相同的對象。原因在於</SPAN><SPAN lang=EN>16</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位的</SPAN><SPAN lang=EN>Windows</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中,</SPAN><SPAN lang=EN>HMODULE</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN>HINSTANCE</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">用於標識不同的東西。</SPAN></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p><FONT size=4>&nbsp;</FONT></o:p></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=4><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">當你在</SPAN><SPAN lang=EN>vc</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的環境裏的</SPAN><SPAN lang=EN>link</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">裏</SPAN><SPAN lang=EN>category</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">選</SPAN><SPAN lang=EN>ouput</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有個</SPAN><SPAN lang=EN>base ,</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">這標識着可執行文件的映像加載到的基地址</SPAN><FONT color=#ff0000><SPAN lang=EN>.vc</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鏈接程序使用的默認基地址是</SPAN><SPAN lang=EN>0x00400000,</SPAN></FONT><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT color=#ff0000>這是最低地址</FONT>,如果指定應確保在</SPAN><SPAN lang=EN>0x00400000</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">或大於這個地址。</SPAN></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><o:p><FONT size=4>&nbsp;</FONT></o:p></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=4><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">要得到這個地址的值可以用</SPAN><SPAN lang=EN>HMODULE GetModuleHandle(PCTSTR pszModule)</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函數處理。</SPAN></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=4><SPAN lang=EN>pszModule</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就是可執行文件或</SPAN><SPAN lang=EN>dll</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件的名字,返回就是加載到進程的基地址。如果設定此參數爲</SPAN><SPAN lang=EN>NULL, </SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">返回的就是可執行文件的基地址了。</SPAN></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=4><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">注意</SPAN><SPAN lang=EN>:</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可執行文件映像的基地址與可執行文件的基地址的區別</SPAN><SPAN lang=EN>.</SPAN></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT color=#ff0000><FONT size=4><SPAN lang=EN>GetModuleHandle</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函數的兩個重要特性</SPAN></FONT></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT color=#ff0000><FONT size=4><SPAN lang=EN>1.</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果調用進程不使用常用的對話框函數</SPAN><SPAN lang=EN>,</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">那麼調用</SPAN><SPAN lang=EN>GetModuleHandle</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">併爲它傳遞</SPAN><SPAN lang=EN>:ComDlg<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:chmetcnv TCSC="0" NumberType="1" Negative="False" HasSpace="False" SourceValue="32" UnitName="&#8221;" w:st="on">32&#8221;</st1:chmetcnv></SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">後</SPAN><SPAN lang=EN>,</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就會返回</SPAN><SPAN lang=EN>NULL, </SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">儘管</SPAN><SPAN lang=EN>ComDlg32.dll</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可能加載到了其它進程的地址空間</SPAN><SPAN lang=EN>.</SPAN></FONT></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT color=#ff0000><FONT size=4><SPAN lang=EN>2</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">.如果</SPAN><SPAN lang=EN>GetModuleHandle(NULL)</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</SPAN><SPAN lang=EN>dll</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中調用,返回的也是可執行文件的基地址,而不是</SPAN><SPAN lang=EN>DLL</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件的基地址</SPAN><SPAN lang=EN>.</SPAN></FONT></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><o:p><FONT size=4>&nbsp;</FONT></o:p></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT color=#ff1493 size=4>2.進程的命令行</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=4><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">要獲得一個指向進程的完整命令行的指針</SPAN><SPAN lang=EN>,</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以用</SPAN><SPAN lang=EN>GetCommandLine</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函數</SPAN></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><FONT size=4>GetCommandLine();</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=4><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函數返回一個指向包含完整命令行的緩存的指針</SPAN><SPAN lang=EN>,</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是個完整路徑名</SPAN><SPAN lang=EN>.</SPAN></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><o:p><FONT size=4>&nbsp;</FONT></o:p></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=4><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">再介紹個函數</SPAN><SPAN lang=EN><FONT color=#ff0000>CommandLineToArgv</FONT>,</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">它是將字符串分割成它的各個標記</SPAN><SPAN lang=EN>,</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比如</SPAN><SPAN lang=EN>argc,</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其返回一個字符串指針的數組</SPAN></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><FONT size=4>PWSTR CommandLineToArgv(PWSTR pszCmdLine, int* pNumArgs);</FONT></SPAN></P><SPAN lang=EN><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=4><SPAN lang=EN>pNumArgs</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是整數地址</SPAN><SPAN lang=EN>,</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">設置爲命令行中參數的數目</SPAN><SPAN lang=EN>.</SPAN></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=4><SPAN lang=EN>CommaneLineToArgv</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">負責在內部分配內存</SPAN><SPAN lang=EN>,</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">應用程序不釋放該內存</SPAN><SPAN lang=EN>,</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">它是在進程運行終止時由</SPAN><SPAN lang=EN>os</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">來釋放的</SPAN><SPAN lang=EN>,</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果子自已來釋放</SPAN><SPAN lang=EN>,</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">應用</SPAN><SPAN lang=EN>HeapFree</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函數</SPAN></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><o:p><FONT size=4>&nbsp;</FONT></o:p></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT color=#ff1493 size=4>3.進程的環境變量</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=4><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">每個進程都有一個與它相關的環境塊</SPAN><SPAN lang=EN>.</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">環境塊是進程的地址空間中分配的一個內存塊</SPAN><SPAN lang=EN>.</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">每個環境塊都包含一組字符串</SPAN><SPAN lang=EN>.</SPAN></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=4>例如</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><FONT size=4>VarName1 = VarValue1/0</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><FONT size=4>VarName2 = VarValue2/0</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><FONT size=4>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><FONT size=4>/0</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=4>注意</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=4>例如</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><FONT size=4>XYZ= Windows</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><FONT size=4>ABC=Windows</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=4><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">雖然</SPAN><SPAN lang=EN>XYZ</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">與</SPAN><SPAN lang=EN>ABC</SPAN><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有相同的值,但二者是不同的</SPAN><SPAN lang=EN>.</SPAN></FONT></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><FONT size=4>XYZ =Home</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN><FONT size=4>XYZ=Work</FONT></SPAN></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=4>也是不同的,中間的空格區別了它們

Win98的環境變量寫在了autoexec.bat

Win2000中環境變量的名在

HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/SessionManager/Environment

值寫在了

HKEY_CURRENT_USER/Environment

只有擁有管理員的身份纔可能對其進行修改。

使用DWORD GetEnvironmentVariable(PCTSTR pszName, PTSTR pszValue, DWORD cchValue);可以確定某個環境變量是否存在以及它的值。

第一個參數爲名稱,第二個爲存放變量值的緩存, 第三個參數爲緩存的大小(用字符數來表示)

BOOL SetEnvironmentVariable(PCTSTR pszName, PCTSTR pszValue)修改與添加,刪除變量,如果不存在pszName這樣的變量就添加一個新的變量,如何存在就修改爲pszValue。如果pszValueNULL,就刪除此變量。

 

4.進程的親緣性

進程中的線程可以在主計算機中的任何一個CPU上執行。但是一個進程的線程可能被強制在可用CPU的子集上運行,這就叫進程的親緣性。

 

5.進程的錯誤模式

UINT SetErrorMode(UINT fuErrorMode);

表要加上

CreateProcess裏有一個參數指定了這個,使子進程錯誤如何處理

進程的當前驅動器和目錄

如果調用CreateFile打開一個文件(不設定路徑),那麼系統就在當前驅動器和目錄中查找該文件。用DWORD GetCurrentDirectory(DWORD cchCurDir, PTSTR pszCurDIr)可以得到

BOOL SetCurrentDirectory(PCTSTR pszCurDir); 可以指定路徑。

 

6.進程的當前目錄

系統對進程的當前驅動器與目錄保持跟蹤,但它不跟蹤每個驅動器的當前目錄。這種支持是通過進程的環境字符串來提供的。例如進程有下面的兩個環境變量。

=C:=C:/Utility/Bin

=D:=D:/Program Files

上面表示,驅動器C的進程的當前目錄是/Utility/Bin, D的是/Program Files;

如果調用一個函數,傳遞一個驅動器全名,但不是當前的驅動器,那麼系統就查看進程的環境塊,找出與指定驅動器名相關的變量。如果存在,系統將該變量的值用作當前驅動器。如果不存在,系統將假設指定驅動器的當前目錄是它的根目錄。

例如進程的當前目錄是C:/Utility/Bin,但調用CreateFile打開D:ReadMe.txt, 那麼系統查看環境變量=D.如果=D存在,系統就從D:/Program File目錄打開該ReadMe.txt文件。如果=D不存在,系統將從驅動器D的根目錄來打開ReadMe.txt

 

待續...............

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章