This is the mail archive of the
cygwin-developers
mailing list for the Cygwin project.
Re: Avoid collisions between parallel installations of Cygwin
On Oct 16 12:20, Dave Korn wrote:
> Corinna Vinschen wrote:
>
> > Well, not really, apparently. However, can't we use the
> > BeginUpdateResource, UpdateResource and EndUpdateResource calls?
>
> Yep, they look like they'll do the job.
I'm just experimenting with them using Chuck's example code as base.
Apparantly you can't change your own executable with these calls. If
you try, you get an ERROR_ACCESS_DENIED from EndUpdateResource.
And then I'm just puzzeled by this. I load the resource from a copy of
the executable (foo-copy.exe), and write it back unchanged to the copy
of the executable:
HMODULE hMod = LoadLibraryEx ("foo-copy.exe", NULL, LOAD_LIBRARY_AS_DATAFILE);
HRSRC hRes = FindResource (hMod, CYGPROPS_RES_NAME, RT_RCDATA);
HGLOBAL hglb = LoadResource(hMod, hRes);
orig_lpcygprops = lpcygprops = LockResource(hglb);
[...]
HANDLE hupdate = BeginUpdateResource ("foo-copy.exe", FALSE);
if (hupdate)
{
if (!UpdateResource (hupdate, RT_RCDATA, CYGPROPS_RES_NAME,
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
&orig_lpcygprops, SizeofResource (hMod, hRes)))
{
fprintf(stderr, "UpdateResource: %lu\n", GetLastError ());
EndUpdateResource (hupdate, TRUE);
}
else if (!EndUpdateResource (hupdate, FALSE))
fprintf(stderr, "EndUpdateResource: %lu\n", GetLastError ());
}
else
fprintf(stderr, "BeginUpdateResource: %lu\n", GetLastError ());
UnlockResource (hglb);
FreeResource (hglb);
This seems to work fine at first:
$ ./foo
BEFORE:
allow_multiple: 0x0000
something_else: 0x0000
extra_sz : 0x0000
extra : <NULL>
AFTER:
allow_multiple: 0x0001
something_else: 0x0002
extra_sz : 0x0007
extra : 0xaa 0xbb 0x55 0x44 0xcc 0xdd 0x22
But the next call doesn't look that nice anymore:
$ ./foo
BEFORE:
allow_multiple: 0x0000
something_else: 0x0000
extra_sz : 0x0000
extra : <NULL>
AFTER:
bad cygprops version; expected 1 got 6252
Huh? I didn't change the resource, I just write it back! WTF?
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com
Red Hat