From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Gary V. Vaughan" To: Geoffrey Noer Cc: Jorrit Tyberghein , gnu-win32@cygnus.com, Christian Jullien Subject: dlopen patch [was Re: dlopen] Date: Wed, 11 Nov 1998 03:57:00 -0000 Message-id: <364883FA.B4BB64EA@oranda.demon.co.uk> References: <36386742.E14F6F22@uz.kuleuven.ac.be> <3639AEEB.855AC45C@oranda.demon.co.uk> <19981030161916.56800@cygnus.com> X-SW-Source: 1998-11/msg00475.html Geoffrey Noer wrote: > > On Fri, Oct 30, 1998 at 12:19:55PM +0000, Gary V. Vaughan wrote: > > > > Geoffrey, I notice that the dlopen emulation doesn't handle a NULL > > argument as per the POSIX spec (i.e. return an introspective handle > > to the current process), yet the win32 GetModuleHandle does... will > > this be fixed for b20? Too late for a patch? > > Yep, much too late. I will gladly take a patch after b20 is out > however... Better late than never? Diffs attached. Interestingly, this doesn't seem to fix my particular problem -- but unless there is funkiness with casting from HMODULE (dlopen) to void* (dlsym) to HINSTANCE (GetProcAddress), then by inspection it really ought to work, according to the Borland Win32 API docs. I guess my implementation is awry somehow. Cheers, Gary V. Vaughan --- dlfcn.cc.orig Tue Nov 10 11:58:45 1998 +++ dlfcn.cc Tue Nov 10 12:07:11 1998 @@ -127,9 +127,21 @@ get_full_path_of_dll (const char* str) void * dlopen (const char *name, int) { - const char *fullpath = get_full_path_of_dll (name); - DllList::the().currentDlOpenedLib (fullpath); - void *ret = (void *) LoadLibrary (fullpath); + void *ret = 0; + + if (!name) + { + // handle for the current module + ret = (void *) GetModuleHandle (0); + } + else + { + // handle for the named library + const char *fullpath = get_full_path_of_dll (name); + DllList::the().currentDlOpenedLib (fullpath); + ret = (void *) LoadLibrary (fullpath); + } + if (!ret) set_dl_error ("dlopen"); debug_printf ("ret %p", ret);