Bueno, cree un programa con una variable llamada IP y al inicio hace
Msgbox IP
OK, el codigo de COBEIN del cual hablo es el edit generic sever o alreves ahora no se x'D bueno y en otro programa pongo:
Dim txtIP As String
Dim txtPort As String
Dim sRuta As String
'---------------------------------------------------------------------------------------
' Module : cEditSvr
' DateTime : 19/09/2008 13:23
' Author : Cobein
' Mail : cobein27@hotmail.com
' WebPage : http://www.advancevb.com.ar
' Purpose : Read Write data at EOF
' Usage : At your own risk
' Requirements: None
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
'
' History : 19/09/2008 First Cut....................................................
'---------------------------------------------------------------------------------------
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private c_pBag As New PropertyBag
Private c_sFile As String
Private c_lEOF As Long
Public c_bHasData As Boolean
'---------------------------------------------------------------------------------------
' Procedure : GetEOF
' Author : E0N
' Purpose : Calculate EOF
'---------------------------------------------------------------------------------------
Private Function GetEOF(sPath As String) As Long
Dim vbData() As Byte
Dim PE As Long, NumberOfSections As Integer
Dim BeginLastSection As Long
Dim RawSize As Long, RawOffset As Long
Open sPath For Binary As #1
ReDim vbData(LOF(1) - 1)
Get #1, , vbData
Close #1
Call CopyMemory(PE, vbData(&H3C), 4)
Call CopyMemory(NumberOfSections, vbData(PE + &H6), 2)
BeginLastSection = PE + &HF8 + ((NumberOfSections - 1) * &H28)
Call CopyMemory(RawSize, vbData(BeginLastSection + 16), 4)
Call CopyMemory(RawOffset, vbData(BeginLastSection + 20), 4)
GetEOF = RawSize + RawOffset
End Function
Public Function ExeFile(sPath As String) As Boolean
c_sFile = sPath
c_lEOF = GetEOF(c_sFile)
If Not FileLen(c_sFile) = c_lEOF Then
c_bHasData = True
Dim vbData() As Byte
Open c_sFile For Binary As #1
ReDim vbData(LOF(1) - c_lEOF - 1)
Seek #1, c_lEOF + 1
Get #1, , vbData
Close #1
'+++++++++++++++++++++++++++++++++++++++++++++++++++++
'At this point you can Decrypt the byte array [vbData]
'+++++++++++++++++++++++++++++++++++++++++++++++++++++
Set c_pBag = New PropertyBag
c_pBag.Contents = vbData
End If
End Function
Public Sub WriteProp(sName As String, vVal As Variant)
c_pBag.WriteProperty sName, vVal
End Sub
Public Function ReadProp(sName As String) As Variant
ReadProp = c_pBag.ReadProperty(sName)
End Function
Public Function WriteData(sDstFile As String) As Boolean
Dim vbData() As Byte
Open c_sFile For Binary Access Read As #1
ReDim vbData(LOF(1) - 1)
Get #1, , vbData
Close #1
Open sDstFile For Binary Access Write As #1
Put #1, , vbData
vbData = c_pBag.Contents
'+++++++++++++++++++++++++++++++++++++++++++++++++++++
'At this point you can Encrypt the byte array [vbData]
'+++++++++++++++++++++++++++++++++++++++++++++++++++++
Put #1, , vbData
Close #1
End Function
Private Sub Command1_Click()
'txtIP = Text1.Text
'txtPort = Text2.Text
'CD.Filter = "Solo *.exe |*.exe"
'CD.ShowOpen
Dim c As New cEditSvr
CD.ShowOpen
sRuta = CD.FileName
c.ExeFile = sRuta
c.WriteProp "IP", "1111"
CD.ShowSave
c.WriteData = CD.FileName
Set c = New cEditSvr
CD.Filter = "Solo *.exe |*.exe"
c.ExeFile = CD.FileName
Debug.Print c.ReadProp("IP")
End Sub
y cuando apreto el command me dice que
Dim c As New cEditSvr
No esta definida.
¿Alguien sabe xk?
Grax :)
cEditSvr, que es una clase?
Tienes que poner el código de cobein en un módulo de clase.
Saludos.
Bueno ya lo hice y no me da error ahi ! Pero si en otro ! Cambié el codigo de llamada mirad y decidme el error:
Private Sub Command1_Click()
'txtIP = Text1.Text
'txtPort = Text2.Text
Dim c As New cEditSvr
CD.ShowOpen
c.ExeFile CD.FileName '¿Exe file que es? Es donde esta el programa al cual escribimos?
c.WriteProp "IP", "1111"
c.WriteData "c:\test.exe" '¿Aqui esta ruta que es?
Set c = New cEditSvr
c.ExeFile "c:\text.exe" '¿Aqui esta ruta que es?
Debug.Print c.ReadProp("IP")
End Sub
Bueno lo que no se de ahi son los '
y cuando lo abro y selecciono el programa para que lo escriba me da este error en el modulo
Subscript ouft Range --> ReDim vbData(LOF(1) - 1)
¿Alguien sabe porque? Gracias
Me fijé en los comentarios:
- En c.ExeFile debes poner la ruta del ejecutable donde quieres insertar los datos. Por ejemplo, si haces que el servidor se cree desde el archivo de recursos, puedes poner la ruta del archivo extraído de los recursos.
- En c.WriteData debes poner la ruta del ejecutable final. Si haces lo que te comenté antes, debes poner la misma ruta.
No hace falta que pongas Set c = New cEditSvr
Saludos.
OK, Ya me rulo ! No me dio error, pero el programa que cree que hace un MsgBox con la variable IP me saco un mensaje vacio, no deberia habermelo sacado con 1111 ¿? Gracias.
¿Cuál es el código del programa que debe leer la IP?
Dim IP As String
Private Sub Form_Load()
MsgBox IP
End Sub
eso q has puesto es la funcion para enseñarla en el msgbox no para obtenerla..
saludos
y como se obtiene? Gracias.
Sería algo así:
Private Sub Form_Load()
Dim c As New cEditSvr
Dim IP As String
c.ExeFile App.Path & "\" & App.EXEName & ".exe"
IP = c.ReadProp("IP")
MsgBox IP
End Sub
Tienes que agregar la clase en el programa con el que lo lees.
Saludos.
OK !!! Ya me funciona !! Muchisimas gracias a todos !! :) ;D ;D ;D ;D ;D