Koen van de Sande
21st October 2002 12:02 UTC
VPatch plugin for NSIS: question
I've been working on converting the VPatch exe runtime to a DLL compatible with NSIS, but I have a problem with correct 'initialization' of my filenames which I pop of the stack.
The following *does not* work, however I'm not sure how to change it (since with the old way, additional libraries were required).
{
char *source = "";
char *dest = "";
char *exename = "";
HANDLE hPatch, hSource, hDest;
int result;
popstring(exename);
MessageBox(g_hwndParent,exename,0,MB_OK);
popstring(source);
MessageBox(g_hwndParent,source,0,MB_OK);
popstring(dest);
MessageBox(g_hwndParent,dest,0,MB_OK);
MessageBox(g_hwndParent,exename,0,MB_OK);
MessageBox(g_hwndParent,source,0,MB_OK);
MessageBox(g_hwndParent,dest,0,MB_OK);
In the last 3 lines, all filenames are the same...
I've attached the complete project. What is the correct way to do this?
Thanks for any help you can give!
Koen van de Sande
21st October 2002 12:30 UTC
I found it... using "static char exename[1024];" does the trick.
I've removed the bugged version from the post above, and attached a working version of the plugin with this post.
You can now use this VPatch DLL in your installer: put VPatch.dll in your plugin directory, and in the installer you can use it like this:
vpatch::vpatchfile (Patchfile) (sourcefile) (outputfile)
The result will be pushed onto the stack; if it begins with "OK", then all is well. You just need to rename outputfile to sourcefile yourself (if outputfile exists).
kichik
24th October 2002 21:11 UTC
Use static char bla[MAX_PATH].
Explanation below
Koen van de Sande
24th October 2002 21:24 UTC
MAX_PATH? Didn't know there was such a constant. I'll change it in the next version. Thanks.
kichik
24th October 2002 22:33 UTC
MAX_PATH is the shell's maximum length of a path string.
You need to define those variables as char name[] because char *name is just a pointer. When you first define it, it points to nothing. You have to give it somewhere to point to or else weird things will happen and memory that shouldn't be written to will be replaced by unwated values. When you use char bla[512] you will get a block the size of 512 bytes. In there a string can be written without overriding other data which probably is critical.