Hi,
I was wondering if you can add a help file (.chm file) & a .dll file to a resource.
If you can, how do I add them into a resource and get the program to use them?
For the help file, I simply use System "myhelpfile.chm" and windows will open it.
Just trying to cut down on the number of files needed for a program.
Thanks,
Andy.
Sure you can.
Here's how I do it:
In my rc file:
303 324 "C:\\myproject\\my.chm"
304 324 "C:\\myproject\\my.dll"
where 303/304 are unique IDs in my program
and 324 is a custom resource type number I picked above 255
so it will not interfere with any of the predefined types.
In my program to extract the files:
ExtractResource(303, 324, getstartpath+"my.chm")
ExtractResource(304, 324, getstartpath+"my.dll")
and my subroutine to extract the files:
global SUB ExtractResource(id:INT, restype:INT, filename:STRING)
BFILE f
MEMORY m
INT retc
retc = 0
if loadresource(id, restype, m)
if openfile(f, filename, "w")=0
retc = __write(f, m, LEN(m)-1)
closefile f
endif
freemem m
endif
return
ENDSUB
Larry,
Like that a lot! Gonna use that right now...
Brian
Thanks as always Larry,
I've got the help file included, no problem, but I can't get the dll working.
It's the Shape2LM.dll for your custom buttons.
After compile, windows just come up with an error saying it can't fine the dll and the .rc file is correct as you wrote.
This is added to the main source code file:
$MAIN
ExtractResource(303, 324, getstartpath+"autosafediagnostics.chm")
ExtractResource(304, 324, getstartpath+"Shape2LM.dll")
$INCLUDE "globals.iwb"
GLOBAL SUB ExtractResource(id:INT, restype:INT, filename:STRING)
BFILE f
MEMORY m
INT retc
retc = 0
if loadresource(id, restype, m)
if openfile(f, filename, "w")=0
retc = __write(f, m, LEN(m)-1)
closefile f
endif
freemem m
endif
return
ENDSUB
I've tried adding the global sub to the "globals.iwb" where everything is defined, and just get error when comiling, It's obviously me, big fan now of compiling as projects but I can't make the dll section work.
What am I doing wrong here? and what piece of code should be where to make the dll work?
Thanks,
Andy.
my bad; for the dll to have any chance at all of working it has to be extracted before your main window is opened and your program has to go into a tight loop until the dll is actually there and then proceed.
GLOBAL SUB ExtractResource(id:INT, restype:INT, filename:STRING)
...
endsub
would be placed in the globals.iwb file
then you main program would look like this
$include "globals.iwb"
$main
string aa=getstartpath+"Shape2LM.dll"
ExtractResource(303, 324, getstartpath+"autosafediagnostics.chm")
ExtractResource(304, 324, aa)
while FileExist(aa)=0
wend
OPENWINDOW win.......
FileExist is a command in Fletchie's lib.
The point is the dll has to be extracted and in place before you executd any command that uses the dll.
Larry, that's great!
Decided to take it one step further.
I have a setup.exe for the main program, so I've embedded the main program & the dll file into the setup.
So when you run setup, the main program & the dll are extracted, I can do it this way as these two files are not needed until the setup program has finished.
When the setup program has finished, the main program runs and then extracts the help files.
So basically, to setup & run the program a user only needs the one file - setup.exe
Just incase a user has a problem, I will still have all the individual files available to download as an alternative, to cover the setup program not working, although it works for me with no problems.
Thanks,
Andy.