Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / June 2009



Tip: Looking for answers? Try searching our database.

Help with binary file access please.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dos-man 64 - 24 Jun 2009 01:01 GMT
Does anyone see anything wrong with this small program?  I am trying
to read through each byte in a text file script with the binary Get
statement. Then I am trying to use PUT to "poke" each character into
an exe starting at a certain position. It initially worked, but now it
is not working.

Sub Main()
On Error GoTo BigError

If Command$ = "" Then End

REM leave template.exe unaltered
FileCopy fileloc + "template.exe", fileloc + "a.exe"

Open fileloc + "a.exe" For Binary As #1
Open Command$ For Binary As #2

Dim character As String * 1
Dim filepos As Long

filepos = 25947

Dim filelength As Long
filelength = LOF(2)
If filelength > 28000 Then
  MsgBox "Script exceeds 28000 bytes. Compile failed"
  Close
  End
End If

Dim x As Long
For x = 1 To filelength
  Get #2, x, character
  Put #1, filepos, character
  filepos = filepos + 1
Next x

Close #1
Close #2
MsgBox "Task Complete"
End
BigError:
  MsgBox "Compile failed: " + Str$(Err.Number) + "-" +
Err.Description
  Close
  End
End Sub

Function fileloc() As String
' returns path to executable
a$ = App.Path
If a$ <> "\" Then
  a$ = a$ + "\"
End If
fileloc = a$
End Function
Dos-Man 64 - 24 Jun 2009 02:19 GMT
> Does anyone see anything wrong with this small program?  I am trying
> to read through each byte in a text file script with the binary Get
[quoted text clipped - 52 lines]
>  fileloc = a$
> End Function

Never mind.  I don't think it is a problem with this code.  There was
an illegal function call happening within a.exe.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.