El 12/02/11 09:39 p.m., BeeJ escribió:
> My adjunct question got buried in the last post.
> What is the best way to embed a string into the compiled code after
> compilation?
> I would like to put in a serial number of sorts.
> All I can think of is to put in a known string in the source, then
> search the EXE with a different program I write to find that string and
> substitute my unique string. Is there a better way to do this?
> I would have to make multiple copies of my EXE then process all of them
> to embed the replacement. It is all doable but ...
> Is the Resource portion easy to find and modify within the EXE?
May be something like this.
Start a new project and copy this code:
********************************************************
Option Explicit
Private Sub Form_Load()
Dim a As String * 50
a = "EMPTY_STRING______________________________________"
MsgBox "Program compiled with " & a
End Sub
********************************************************
Compile to D:\Project1.exe (or whatever)
Start another project and copy this code:
********************************************************
Option Explicit
Private Sub Form_Load()
Text1.MaxLength = 50
Text1.Text = "Enter the new String here and press enter"
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim iBytes() As Byte
Dim iLen As Long
Dim iStr As String
Dim iPos As Long
Dim iStr50a As String * 50
Dim iStr50b As String * 50
Dim iFilePath As String
If KeyAscii = 13 Then
iFilePath = "d:\project1.exe"
Open iFilePath For Binary Lock Read As #1
iLen = FileLen(iFilePath)
ReDim iBytes(iLen - 1)
Get #1, , iBytes
Close #1
iStr50a = Text1.Text
iStr50b = "EMPTY_STRING______________________________________"
iStr = iBytes
iPos = InStr(iStr, iStr50b)
iStr = Left(iStr, iPos - 1) & iStr50a & Right(iStr, _
Len(iStr) - iPos - 50 + 1)
iBytes = iStr
Open iFilePath & "_customized.exe" For Binary Access Write As #1
Put #1, , iBytes
Close #1
End If
End Sub
********************************************************
Enter something and press Enter. Then run d:\project1.exe_customized.exe