This function allows you to get the running program's temp directory, where all dlls, icons, and the attached 'media'folder are extracted.
This would allow one to call included dlls or use the included icons for other purposes (BlueGUI windows, etc.). It could also be used to dynamically change included media during runtime, although all changes would be lost when the program closes (and the programmer should be careful to delete any new files he creates here during runtime).
Edit: Requires Ian M's
Matrix1Utils plugins. Make sure to get the latest Matrix1Utils_16.dll version 1.0.0.7 near the end of the thread.
Rem temppath$ = getDBPtempPath()
rem requires kernel32.dll loaded as dllnum kernel32num:
#constant kernel32num 5
load dll "kernel32.dll",kernel32num
rem Gets the running program's temp directory, where all dlls, icons, and the
rem attached 'media'folder are extracted. This would allow one to call included dlls
rem or use the included icons for other purposes (BlueGUI windows, etc.).
rem It could also be used to dynamically change included media during runtime,
rem although all changes would be lost when the program closes (and the programmer
rem should be careful to delete any new files he creates here during runtime).
set window on
rem in this example the following two commands are called above, between remarks.
rem You must call these commands, along with whatever number you want to load the dll to,
rem for this function to work.
`#constant kernel32num 5
`load dll "kernel32.dll",kernel32num
starttime = timer()
temppath$ = getDBPtempPath()
timetaken = timer()-starttime
print "DBp Tempt Dir = "+temppath$
suspend for key
end
function getDBPtempPath()
local lp
local temppath as string
local ltempA$ as string
local returnval as string
local prevrundir as string
local mediadirexist
rem don't lose the running directory because of this function
prevrundir = get dir$()
rem but don't let the running dir mess up our results either (would only happen if running dir was other temp DBp media dir
set dir "C:"
lp = 1
rem get the base path
temppath = getWindowsTempPath()
do
rem make sure not to have a folder dbpdata1, else use a numbered one
if lp=1
ltempA$ = temppath+"dbpdatamedia"
else
ltempA$ = temppath+"dbpdata"+str$(lp)+"media"
endif
if path exist(ltempA$)=0
rem need to know whether to delete 'media' upon exit
mediadirexist = 0
rem create the full path if nonexistent
make_path(ltempA$)
else
mediadirexist = 1
endif
rem if there is no test file (normal conditions), make one
if file exist(ltempA$+"TempDirCheck.tmp")=0 then make file ltempA$+"TempDirCheck.tmp"
rem if DBpro can read the test file without the directory and without the file in the
rem running dir, then we've found the extracted media dir, and lp is correct tempnum
if file exist("TempDirCheck.tmp")
if lp=1
returnval = temppath+"dbpdata"
else
returnval = temppath+"dbpdata"+str$(lp)
endif
endif
rem delete our damage
delete file ltempA$+"TempDirCheck.tmp"
if mediadirexist=0 then delete directory ltempA$
rem if we've found it, don't continue!
if returnval<>"" then exit
lp = lp+1
loop
set dir prevrundir
endfunction returnval
function getWindowsTempPath()
rem credits:spooky and IanM
local TempPath as string
`Gets the size that the buffer needs to be
PathLength = call dll(kernel32num,"GetTempPathA",0,0)
`Allocate the buffer (PathLength chars + 1 for the nul byte)
TempPath = space$(PathLength)
`Get the path into the buffer, +1 to hold the terminating nul
PathLength = call dll(kernel32num,"GetTempPathA",PathLength+1,TempPath)
TempPath = fast left$(TempPath,fast len(TempPath)-1)
endfunction TempPath
function make_path(fullpath as string)
local curdir as string
split string fullpath,""
curdir = get split word$(1)
for lp = 2 to split count()
curdir = curdir+""+get split word$(lp)
if path exist(curdir)=0 then make directory curdir
next lp
endfunction
-Xol