Page 1 of 2

Include exe and copy the file

Posted: Sat May 22, 2004 9:07 pm
by GeoTrail
I'm trying to make a simple update program for a project.
So I need to inlclude an updated exe file in the update program and then be able to copy the file to it's destination.

Code: Select all

CopyFile(?file,"C:\filename.exe")


DataSection 
file:
IncludeBinary "filename.exe" 
fileend: 
EndDataSection
That is what I got so far.
Could someone please help me with this?

Posted: Sat May 22, 2004 9:28 pm
by GPI
Try CreateFile(), WriteData(),CloseFile()...

Posted: Sat May 22, 2004 9:50 pm
by GeoTrail
Could you please give me an example how those functions could be used with my code?

I tried this but it only makes an empty file:

Code: Select all

Result = CreateFile(0, "filename.exe")
WriteData(*MemoryBuffer, ?File)
CloseFile(0)


DataSection 
File:
IncludeBinary "filename.exe" 
fileend: 
EndDataSection

Posted: Sat May 22, 2004 10:29 pm
by GeoTrail
Anyone? Please?

Code: Select all

CreateFile(0, "filename.exe")

WriteData(?File,Length)
CloseFile(0)


DataSection 
File:
IncludeBinary "filename.exe" 
Fileend: 
EndDataSection
The include thing works, I see that the compiled exe gets alittle bigger than the included file. But I can't seem to write the file to disk.

Anyone?
PLEASE??

Posted: Sat May 22, 2004 10:33 pm
by Polo
not sure, but you haven't defined length.

Posted: Sat May 22, 2004 10:37 pm
by GeoTrail
I know, I don't know how to do that.
I've tried Lof() but it only returns 0 as the file has no content after CreateFile()

Posted: Sat May 22, 2004 10:40 pm
by Polo

Code: Select all

a=OpenFile(#PB_ANY, ?File)
Length=Lof()
CloseFile(a)


CreateFile(0, "filename.exe") 

WriteData(?File,Length) 
CloseFile(0) 


DataSection 
File: 
IncludeBinary "filename.exe" 
Fileend: 
EndDataSection
I haven't checked if it works, but it's supposed to :wink:

Posted: Sat May 22, 2004 10:41 pm
by GPI
Try:

Code: Select all

CreateFile(0, "filename.exe")

WriteData(?File,?fileend-?file)
CloseFile(0)


DataSection 
File:
IncludeBinary "filename.exe" 
Fileend: 
EndDataSection

Posted: Sat May 22, 2004 10:47 pm
by GeoTrail
Polo wrote:

Code: Select all

a=OpenFile(#PB_ANY, ?File)
Length=Lof()
CloseFile(a)


CreateFile(0, "filename.exe") 

WriteData(?File,Length) 
CloseFile(0) 


DataSection 
File: 
IncludeBinary "filename.exe" 
Fileend: 
EndDataSection
I haven't checked if it works, but it's supposed to :wink:
I get this errormessage when trying to compile:
Bad parameter type: a string is extected.

Posted: Sat May 22, 2004 10:51 pm
by GeoTrail
GPI wrote:Try:

Code: Select all

CreateFile(0, "filename.exe")

WriteData(?File,?fileend-?file)
CloseFile(0)


DataSection 
File:
IncludeBinary "filename.exe" 
Fileend: 
EndDataSection
That worked great :) Thanks.
Only thing is, it generates a Windows error while running the program.
The filename.exe file works great.

Posted: Sat May 22, 2004 11:33 pm
by eriksradio
This works for me if it is any help


If CreateFile(1, "filename.exe")
UseFile(1)
L1 = ?ExitProc - ?Inc
WriteData(?Inc, L1)
CloseFile(1)
Goto BeginProgram1
Inc :
IncludeBinary "filename.exe"
exitProc:
EndIf

BeginProgram1:

Posted: Sun May 23, 2004 12:08 am
by GeoTrail
Thanks eriksradio.
That worked great. No error :)

Any idea why

Code: Select all

CreateFile(0, "filename.exe") 

WriteData(?File,?fileend-?file) 
CloseFile(0) 


DataSection 
File: 
IncludeBinary "filename.exe" 
Fileend: 
EndDataSection
causes an error? I've tried it on both Win2000 and WinXP, both reports an error.

Posted: Sun May 23, 2004 3:09 am
by eriksradio
Sorry Geo, I don't really know.

I got this example from the PURE AREA site.
I downloaded the complete Code Archive
There is a wealth of info and examples there, a must have
for newbies like me.

I program mostly in VB.
When I can't do it in VB, I can usually do it and more in PB

Have fun

Posted: Sun May 23, 2004 5:09 am
by filperj
No error for me, with xp home and PB 3.90. :roll:
Wich PB version do you use?

Posted: Sun May 23, 2004 11:50 am
by GeoTrail
I use v3.91 beta and jaPBe for 3.91b