自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

VB.NET Windows API函數(shù)兩步通

開發(fā) 后端
這里就使用DllImport特征類來申明VB.NET Windows API函數(shù)還有使用“Declare”語句來申明Windows API函數(shù)做出全面的講解。

VB.NET經(jīng)過長時間的發(fā)展,很多用戶都很了解VB.NET Windows API函數(shù)了,這里我發(fā)表一下個人理解,和大家討論討論。VB.NET要實現(xiàn)查看文件中的圖標,目前只使用.Net FrameWork SDK是無法實現(xiàn)這種功能的,正如前面所說,主要是由于.Net FrameWork SDK推出的時間較短,其功能還不可能面面俱到。

#T#解決問題的關鍵是正確使用Windows API函數(shù),其中所涉及到的Windows API函數(shù)主要有二個:其一是獲得指定文件中的圖標數(shù)目;其二是從指定文件的指定位置導出圖標的Windows句柄。這二個函數(shù)都位于 “Shell32.dll”文件中,并且函數(shù)的入口點都為“ExtractIcon”。下面是在VB.NET中分別使用DllImport特征類和“Declare”語句申明這二個VB.NET Windows API函數(shù)的具體方法。

1.使用DllImport特征類來申明VB.NET Windows API函數(shù)

下面是在VB.NET中使用DllImport特征類申明二個Windows API函數(shù)的具體示例:

  1. 函數(shù)ExtractIcon,其功能是是從指定文件的指定位置導出圖標的Windows句柄。  
  2. < System.Runtime.InteropServices.DllImport ( "Shell32.dll" , EntryPoint :"ExtractIcon" ) > _  
  3. Public Function _  
  4. ExtractIcon ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As UInt32 ) As System.IntPtr  
  5. End Function  
  6. '函數(shù)Icon_Num,其功能是獲得指定文件中的圖標數(shù)目  
  7. < System.Runtime.InteropServices.DllImport ( "Shell32.dll" , EntryPoint :"ExtractIcon" ) > _  
  8. Public Function _  
  9. Icon_Num ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As Integer ) As Integer  
  10. End Function  

在使用DllImport特征類申明Windows API函數(shù)時,如果申明的函數(shù)名稱和函數(shù)的入口點相同,則可以在申明Windows API函數(shù)時,省略定義函數(shù)入口點對應的代碼,即EntryPoint對象字段對應的代碼,這樣聲明ExtractIcon函數(shù)的代碼也可以簡化為如下所示:

  1. < System.Runtime.InteropServices.DllImport ( "Shell32.dll" ) > _  
  2. Public Function _  
  3. ExtractIcon ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As UInt32 ) As System.IntPtr  
  4. End Function 

2.使用“Declare”語句來申明Windows API函數(shù)

使用“Declare”語句的確比使用DllImport特征類要簡單了許多,下面是在VB.NET中使用“Declare”語句來聲明上述二個Windows API函數(shù)的具體方法:

  1. Declare Auto Function ExtractIcon Lib "Shell32.dll" Alias "ExtractIcon"   
  2. ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As UInt32 ) As System.IntPtr  
  3. '聲明ExtractIcon函數(shù)  
  4. Declare Auto Function Icon_Num Lib "Shell32.dll" Alias "ExtractIcon"   
  5. ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As Integer ) As Integer  
  6. '聲明Icon_Num函數(shù) 

在VB.NET中聲明Windows API函數(shù)時,“Declare”語句中Alias關鍵字的作用相當于使用DllImport特征類中的EntryPoint對象字段。同樣在使用 “Declare”語句聲明Windows API函數(shù)時,如果聲明的函數(shù)和函數(shù)的入口點相同,也可以省略Alias關鍵字對應的代碼,所以ExtractIcon函數(shù)也可以簡化為如下:

  1. Declare Auto Function ExtractIcon Lib "Shell32.dll"   
  2. ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As UInt32 )   
  3. As System.IntPtr 

下面就結合一個示例的編寫過程來掌握的這二個Windows API函數(shù)的具體使用方法,這個示例的作用就是讀取指定文件中的圖標數(shù)目,并顯示文件中的圖標。

責任編輯:田樹 來源: 博客
相關推薦

2009-10-19 13:34:18

VB.NET條形碼編程

2009-11-03 12:52:38

VB.NET Wind

2009-10-23 10:01:28

VB.NET申明Win

2009-10-26 10:44:27

VB.NET API函

2009-10-20 09:42:16

VB.NET編程

2009-10-15 17:50:48

VB.NET調用API

2009-10-19 17:42:31

VB.NET API函

2009-10-26 10:12:14

VB.NET操作MsA

2009-10-15 17:50:48

VB.NET Spli

2009-10-21 10:45:50

VB.NET Quic

2010-01-18 18:20:49

VB.NET使用API

2010-01-18 10:33:28

VB.NET基本函數(shù)

2009-10-28 15:01:59

VB.NET SHEL

2009-11-02 13:14:18

VB.NET函數(shù)

2009-10-14 17:21:47

VB.NET定制Win

2009-10-12 12:54:58

VB.NET聲明API

2009-11-10 16:55:05

VB.NET調用API

2009-11-03 09:09:19

VB.NET類

2009-10-28 15:38:30

VB.NET網(wǎng)絡

2009-10-21 09:46:13

VB使用ArrayLi
點贊
收藏

51CTO技術棧公眾號