Skip to Content
0
Former Member
Jan 10, 2006 at 04:24 PM

FileExtract - Can anyone spot the deliberate mistake please?

20 Views

Basically, the program includes my add-in along with SAPbouiCOM.dll both embedded.

The code below now extracts SAPbouiCOM.dll perfectly, but my program is condensed to 1Kb!!!

I bet there's something obvious here, but I just can't spot it!

Private Sub ExtractFile(ByVal path As String)

Try

Dim AddonExeFile As IO.FileStream

Dim thisExe As System.Reflection.Assembly

thisExe = System.Reflection.Assembly.GetExecutingAssembly()

Dim sTargetPath As String

Dim sSourcePath As String

Dim sTargetPathdll As String

Dim sFile As System.IO.Stream

sTargetPath = path & "\" & sAddonName & ".exe"

sSourcePath = path & "\" & sAddonName & ".tmp"

sTargetPathdll = path & "\" & "Interop.SAPbouiCOM.dll"

For Each resourceName As String In thisExe.GetManifestResourceNames()

sFile = thisExe.GetManifestResourceStream(resourceName)

If LCase(resourceName) <> LCase("Addoninstaller.Interop.SAPbouiCOM.dll") Then

' Create a tmp file first, after file is extracted change to exe

If IO.File.Exists(sSourcePath) Then

IO.File.Delete(sSourcePath)

End If

AddonExeFile = IO.File.Create(sSourcePath)

Dim buffer() As Byte

ReDim buffer(sFile.Length)

sFile.Read(buffer, 0, sFile.Length)

AddonExeFile.Write(buffer, 0, sFile.Length)

AddonExeFile.Close()

If IO.File.Exists(sTargetPath) Then

IO.File.Delete(sTargetPath)

End If

' Change file extension to exe

IO.File.Move(sSourcePath, sTargetPath)

Else

' Create a tmp file first, after file is extracted change to exe

AddonExeFile = IO.File.Create(sTargetPathdll)

Dim buffer2() As Byte

ReDim buffer2(sFile.Length)

sFile.Read(buffer2, 0, sFile.Length)

AddonExeFile.Write(buffer2, 0, sFile.Length)

AddonExeFile.Close()

End If

Next

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub