From: Jeremy B. <je...@de...> - 2004-04-01 20:14:11
|
There is a much better way to get the full path of your exe. GetModuleFileName(GetModuleHandle(0), buffer, sizeof(buffer)); works for dlls too, but you do need a little more information: GetModuleFileName(hinstDll /* from DllMain or GetModuleHandle("DLLNAME") */ , buffer, sizeof(buffer)); Or if you want to get crazy, you can use some code like this to find the filename of the dll that the current function is in: void *codeaddress = myfunction; // set this to a pointer to a function or a class or a static variable char buf[1000]; MEMORY_BASIC_INFORMATION memInfo; VirtualQueryEx(GetCurrentProcess(), codeaddress , &memInfo, sizeof(memInfo)); if (GetModuleFileName(memInfo.AllocationBase, buf, sizeof(buf))) { printf("The address %x is in the file %s\n", codeaddress, buf); } ----- Original Message ----- From: "Greg Chicares" <chi...@mi...> To: <min...@li...> Sent: Thursday, April 01, 2004 12:57 PM Subject: Re: [Mingw-users] Building DLLs with MingW > Stefan Viljoen wrote: > > > > URL's? Howtos? Idiot's guides? > > Search the web for 'dllhelpers'. Use '-shared', not 'dllwrap'. > My personal preference is to specify export and import declspecs > explicitly (works on other compilers too), though the auto-import > option avoids that and may work for you. > > > I have code that I have compiled into an .EXE that among other things depends > > on knowing it startup directory... > > Probably you're already doing something like this, then: > > char x[MAX_PATH]; > char** p = 0; > GetFullPathName(argv[0], MAX_PATH, x, p); > > Now the startup directory is in 'x'. > > > how will I implement that code in a DLL > > that might reside in the /Windows directory, for example... > > You don't have to put dlls in a system directory if you don't want. > > > but that I still > > want to access files in the associated .EXE's startup directory? > > You could define a variable for the path inside the dll, and have > the exe set that variable to the value you want. There may be a > simpler way, but this way works. > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > MinGW-users mailing list > Min...@li... > > You may change your MinGW Account Options or unsubscribe at: > https://lists.sourceforge.net/lists/listinfo/mingw-users > |