Accessing embedded files can have problems
FoxPro allows users to embed files into an APP or EXE file using the project manager. That means an icon or JPG can be embedded inside so it can’t be used externally except by the application. However, there is a bug in some file functions that attempt to read the embedded file in certain scenarios. A simple workaround is to make a temporary copy of the file on disk and use that copy. Another workaround is to keep the file on disk and not to embed the file at all.
The code below builds a project called Test2, embeds an icon file, builds test2.exe, and runs it. The code opens and displays the sizes of the embedded icon file and the copy on disk. If you run it, the Embedded Size will show some random number, whereas one would expect the two to be the same.
SET SAFETY OFF
CLOSE DATABASES all
CLEAR
ERASE test2.*
#define ICONFILE HOME(0)+"graphics\icons\computer\disk01.ico"
#define PHYSICON "temp.ico"
COPY FILE ICONFILE TO PHYSICON && make temporary copy that is physically on disk
TEXT to xmyvar && create code for test2.exe
hnd=FOPEN(ICONFILE,10) && open unbuffered, readonly
nSize=FSEEK(hnd,0,2) && Seek to EOF returns file size
FCLOSE(hnd)
hnd=FOPEN(PHYSICON,10) && open unbuffered, readonly
nSize2=FSEEK(hnd,0,2)
FCLOSE(hnd)
MESSAGEBOX("Embedded Size = "+TRANSFORM(nSize)+" Size on Disk="+TRANSFORM(nSize2),0,_vfp.FullName)
ENDTEXT
STRTOFILE(xmyvar,"test2.prg")
BUILD PROJECT test2 FROM test2
MODIFY PROJECT test2 nowait
_vfp.ActiveProject.Files.Add(ICONFILE) && embed the icon. Comment out this line and it works
_vfp.ActiveProject.Close
BUILD EXE test2 FROM test2
!/n test2
Comments
- Anonymous
July 21, 2005
Calvin,
Would this file bug qualify as a Sedna type service pack fix?
I enjoy reading your blog - you're posts always inspire some new code on my end.
Thanks,
Malcolm - Anonymous
July 21, 2005
Consideration for fixing depends on many things: impact on product, severity of problem, severity of fix, available workarounds, etc.
This particular issue was reported as a problem with BUILDING an EXE from within an EXE using an embedded Icon inside the EXE
I'm glad you like my blog. Positive feedback encourages more production!
Thanks Malcolm - Anonymous
August 01, 2007
The comment has been removed