From: vance AT deneb DOT com (Stephen Vance) Subject: Re: [Q] How to load dll's at runtime 25 Sep 1998 09:14:26 -0700 Message-ID: <360A8135.68EF870E.cygnus.gnu-win32@deneb.com> References: <36091F33 DOT EB433757 AT oranda DOT demon DOT co DOT uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: "Gary V. Vaughan" Cc: John vanVlaanderen , Sergey Okhapkin , gnu-win32 AT cygnus DOT com Gary V. Vaughan wrote: > Hi Stephen, thanks for the response! And your's too Sergey, I have read > everything from the cygnus web site that seemed relevant now. [ ... ] > > Here's a code snippet: > > > > void *open_symbol( const char *libname, const char *funcname ) > > { > > > > void *libhandle; > > > > libhandle = dlopen( libname, RTLD_LAZY ); > > if( libhandle == NULL ) > > return NULL; > > > > return dlsym( libhandle, funcname ); > > } > > > > int (*func)( int, char *); // For example > > > > func = open_symbol( "mylib.dll", "myfunc" ); > > > > (*func)( myint, mycharstar ); > > > > Invoking dlsym with a NULL libhandle give you a handle to the > > executable. > > dlsym you say? I am used to using > > libhandle = dlopen (NULL, RTLD_NOW|RTLD_LAZY); > > to get an introverted handle. However I don't seem to be able to get > either of them to work. I have followed the execution through with gdb, > and in either case it fails inside cygwin.dll, with > > error: dlopen: Win32 Error #126 > > and > > error: dlsym: Win32 Error #87 > > respectively. I don't know what the error codes mean. Givent that the first call fails, the second is not surprising. Some problems I have encountered in the past are: -- The symbols may not be exported properly using dll_export() if created with the MS tools. This is particularly tricky with C++. -- You may have name mangling issues if you're using C++. -- The semantics and actual functionality of a NULL library handle vary between systems. For example, in HP's shlib library (they don't use dlopen and friends) NULL is an invalid library handle, but they have a special constant that can be used for this purpose. -- PATH on NT, LD_LIBRARY_PATH on most Unices (and I believe Cygwin) and SHLIB_PATH on HP are not set properly. > > On some systems, this means *precisely* the executable > > (Sun, NT); on others it means the executable and any shared library > > explicitly linked with it (SGI, HP). I suspect Cygwin will behave > > the same way as the regular NT stuff. > > Any other clues you might be able to help me with? The only other suggestions I might have are: -- Try getting your introverted handle by explicitly passing argv[0]. -- Try using dlerror to tell you the error in English. > > > I fear that there may be no support for the introspective handler within > b19... but even confirmation of this would be good. > > Thanks for your patience. > > Gary. Good luck. Dynamic loading stuff can be tricky, particularly when portability is an issue. -- Stephen Vance | http://www.deneb.com Deneb Robotics, Inc. | mailto:vance AT deneb DOT com 5500 New King Street | Phone: (248) 267-9696 Troy, MI 48098-2615 | Fax: (248) 267-8585 What is done well is done quickly enough. -Augustus Caesar - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".