loading cygwin1.dll at runtime

Larry Hall (RFK Partners, Inc.) lhall@rfk.com
Fri May 16 22:13:00 GMT 2003


Sebastian Miele wrote:
> Hi,
> 
> I want to add the following feature to an application compiled with
> -mno-cygwin:
> 
>   Every time the application is about to make a system call with a
>   pathname as argument the application should convert the (possibly
>   cygwin/unix) path to the corresponding windows path using
>   cygwin_conv_to_full_win32_path provided by cygwin1.dll, but only if
>   cygwin1.dll is present on the current host.
> 
> In order to do that I need to link cygwin1.dll at runtime and get a
> pointer to cygwin_conv_to_full_win32_path.  I tried to do this by just
> using LoadLibrary/GetProcAddress/FreeLibrary provided by Windows.
> However, the application crashes.  Gdb tells:
> 
>   Program received signal SIGSEGV, Segmentation fault.
>   0x61051931 in getpass ()
>   (gdb) bt
>   #0  0x61051931 in getpass ()
>   #1  0x6104f268 in getpass ()
>   #2  0x61056629 in cygwin_conv_to_full_win32_path ()
>   #3  0x00401423 in main (argc=2, argv=0x3f24e8) at t.c:21
> 
> Maybe I am missing a call to an initialization routine.  Here is a
> complete compilable example:
> 
>   #include <stdio.h>
>   #include <Windows.h>
>   
>   typedef void (*conv_fun_t) (const char*, char*);
>   
>   int main(int argc, char* argv[])
>   {
>     if (argc!=2) { fprintf(stderr,"fucking arguments\n"); return 1; }
>     const char* input_path= argv[1];
>   
>     HMODULE libcygwin;
>     conv_fun_t cygwin_conv_to_full_win32_path;
>     libcygwin= LoadLibrary("cygwin1.dll");
>     if (libcygwin==NULL) { fprintf(stderr,"fuck1\n"); return 1; }
>     cygwin_conv_to_full_win32_path=
>       (conv_fun_t)(GetProcAddress(libcygwin,"cygwin_conv_to_full_win32_path"));
>     if (cygwin_conv_to_full_win32_path==NULL) { fprintf(stderr,"fuck2\n"); return 1; };
>   
>     char *windows_path= malloc(sizeof(char)*(MAX_PATH+1));
>     fprintf(stderr,"calling cygwin-conv on '%s'\n", input_path);
>     cygwin_conv_to_full_win32_path(input_path,windows_path);
>     printf(windows_path);
>     
>     FreeLibrary(libcygwin);
>     return 0;
>   }
> 
> I compiled the program with
> 
>   gcc -mno-cygwin -g -o t t.c
> 
> Any ideas?

Yeah, use cygpath instead.  Dynamic loading of the Cygwin DLL is
broken and has been for some time now.  PTC. :-)


-- 
Larry Hall                              http://www.rfk.com
RFK Partners, Inc.                      (508) 893-9779 - RFK Office
838 Washington Street                   (508) 893-9889 - FAX
Holliston, MA 01746


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list