Posts
[VB.NET]利用反射載入並運行資源檔中的組件
Module MainModule
<STAThread()> _ Public Sub main(ByVal args() As String) Assembly.Load(My.Resources.ColorPicker).EntryPoint.Invoke(Nothing, New Object() {args}) End Sub End Module
同樣的概念,其實放在資源檔中的組件可以先經過壓縮處理,再放入資源檔中。載入時只要先經過解壓縮的動作,把要執行的組件從壓縮中解出,就可以執行了。 Imports System.IO Imports System.Reflection Imports ICSharpCode.SharpZipLib.Zip
Module MainModule
<STAThread()> _ Public Sub main(ByVal args() As String) Using compressedMS As New MemoryStream(My.Resources.ColorPicker) Dim zf As New ZipFile(compressedMS) Dim ze As ZipEntry = zf.GetEntry("ColorPicker.exe") Dim zs As Stream = zf.GetInputStream(ze) Dim buffer(ze.Size - 1) As Byte zs.Read(buffer, 0, buffer.Length - 1) Assembly.Load(buffer).EntryPoint.Invoke(Nothing, New Object() {args}) End Using End Sub End Module 那若是放在資源檔中的組件需要參考多個組件呢?
read more