VB6 dll 自動編譯工具

xelement發表於2008-01-22

´---------------------------------------------------------------------------------------
´ Module    : VB compiler
´ DateTime  : 03-5-30 15:45
´ Author    : Hardy He
´ Purpose   : VB6 dll 自動編譯工具
´---------------------------------------------------------------------------------------
´ sVBPath : VB6 執行目錄, sOutpath: 輸出dll 目錄, sSourcePath: VB原始檔目錄(包括子資料夾)

Dim sVBPath, sOutpath, sSourcePath
sVBPath = "D:\Program Files\Microsoft Visual Studio\VB98\"
sOutpath = "E:\719\Com\"
sSourcePath = "E:\719\"

Call SearchVbp(sSourcePath)
call DelTempFiles (sOutpath)

´//遍歷目錄得到vbp 工程檔案並編譯
Function SearchVbp(sPath)

   Dim fso, f, f1, fc, s, ff, ff1
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFolder(sPath)
   Set fc = f.Files
   For Each f1 In fc
      If LCase(GetFileExtName(f1.Name)) = "vbp" Then
        MakeDll (f1.Path)       
      End If
   Next
   Set ff = f.Subfolders
   For Each ff1 In ff
        SearchVbp (ff1.Path)
   Next
  
End Function

´// 編譯
Function MakeDll(sVBP)
    Dim oShell
    Set Shell = WScript.CreateObject("WSCript.shell")
    ´msgbox """" & sVBPath & "vb6"" /m """ & sVBP & """ /outdir """ & sOutpath & """"
    oShell.run """" & sVBPath & "vb6"" /m """ & sVBP & """ /outdir """ & sOutpath & """"
    Set Shell = Nothing
End Function

´//刪除臨時檔案
Function DelTempFiles(sPath)
    Dim oShell
    Set Shell = WScript.CreateObject("WSCript.shell")
    ´msgbox "del /q/f " & sOutpath & "*.lib"
    oShell.run "cmd /c del /q/f " & sPath & "*.lib"
    oShell.run " cmd /c del /q/f " & sPath & "*.obj"
    oShell.run " cmd /c del /q/f " & sPath & "*.exp"
    oShell.run " cmd /c del /q/f " & sPath & "*.asp"
    Set Shell = Nothing
End Function

´//得到副檔名
Function GetFileExtName(sFileName)
    Dim ipos, ilen
    ipos = InStr(sFileName, ".")
    ilen = Len(sFileName)
    GetFileExtName = Right(sFileName, ilen - ipos)
End Function

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/778857/viewspace-157090/,如需轉載,請註明出處,否則將追究法律責任。

相關文章