Behaviour of GetModuleFileName

Warren_Baird at cimmetry.com Warren_Baird at cimmetry.com
Tue May 21 09:45:14 CDT 2002




So it looks to me like GetModuleFileName is always returning *only* the filename
of the module, not the full path.   MSDN says:

lpFilename
     [out] Pointer to a buffer that receives the path and file name of the
     specified module.


And I've come across some windows code that relies on this behaviour....  I've
come up with a somewhat messy patch to fix this by adding a call to dlinfo in
the spec code generated by winebuild, but unfortunately there seems to be some
code in wine that relies on GetModuleFileName returning only the filename.  My
current hack is to maintain two versions of winebuild - the one I use when
building wine, and the one I use when building my code...  Hardly elegant.

I have two questions:

  1.  Would anyone object if I tried to fix wine to behave properly with
GetModuleFileName returning the full path?  I haven't dug into it yet, so I
don't know how much effort will be required...  Is there a reasons we have the
current behaviour?

  2.  I've attached the patch I'm using at the bottom of this message - can
anyone think of a cleaner way of doing this?

Thanks!

Warren

-------------------------------------------------------------

--- spec32.c   Thu Apr 11 11:53:35 2002
+++ spec32.c.full_path   Thu Apr 11 11:51:53 2002
@@ -751,12 +751,28 @@
     fprintf( outfile, "#endif /* defined(__GNUC__) */\n\n" );

     fprintf( outfile,
+               "#include <dlfcn.h>\n"
+               "#include <link.h>\n"
              "void __wine_spec_%s_init(void)\n"
              "{\n"
              "    extern void __wine_dll_register( const struct
image_nt_headers *, const char * );\n"
              "    extern void *__wine_dbg_register( char * const *, int );\n"
-             "    __wine_dll_register( &nt_header, \"%s\" );\n",
-             DLLName, DLLFileName );
+               "    char buffer[4096];\n"
+               "    Link_map *p;\n"
+               "    if (dlinfo(RTLD_SELF,RTLD_DI_LINKMAP,&p)) {\n"
+               "      strcpy(buffer,\"%s\");\n"
+               "    } else {\n"
+               "        strncpy(buffer,p->l_name,sizeof(buffer));\n"
+               "        char *tag = strrchr(buffer,'/');\n"
+               "        if (tag) {\n"
+               "            tag +=1;\n"
+               "            strcpy(tag,\"%s\");\n"
+               "        }\n"
+               "        \n"
+               "    }\n"
+               "\n"
+             "    __wine_dll_register( &nt_header, buffer );\n",
+             DLLName, DLLName, DLLFileName,DLLName );
     if (nr_debug)
         fprintf( outfile, "    debug_registration = __wine_dbg_register(
debug_channels, %d );\n",
                  nr_debug );





More information about the wine-devel mailing list