Re: Where is my DLL?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Juergen Luethje wrote:
> 
> Hi all,
> 
> how can a DLL find the path where it was loaded from?
> I need it because the DLL must read an INI file that is in the same
> directory as the DLL. Of course I don't know, where the users will
> install it.
> 
> command_line() is of no use here, because when calling it from a DLL the
> return value obviously is an empty sequence.
> The Win32 API function GetModuleFileName() came to my mind. But if I
> pass NULL to it as the module handle parameter, the function returns
> the path of the EXE file that has called the DLL.
> 
> Somewhere on the internet I read:
> | If you want to find the path for a DLL, pass the DLLs instance handle,
> | which you can obtain from the first parameter in your DLL's DLLMain()
> | function.
> 
> Of course in Euphoria there is no DLLMain() function.
> When I pass the result of Euphoria's instance() function as the module
> handle parameter, GetModuleFileName() also returns the path of the EXE
> file instead the path of the DLL.
> 
> Then I found the API function GetModuleHandle(). This gives me the
> handle of a module, so that I can find its name. As parameter,
> GetModuleHandle() requires the name of the module ... smile)
> 
> Well, that name does not have to specify a path, so this might work to
> some degree. E.g. I can pass "my.dll" to GetModuleHandle(), than pass
> the handle to GetModuleFileName(), and as result I'll get e.g.
> "C:\this\and\that\my.dll".
> 
> This not only seems somewhat crazy to me smile, I think there can be at
> least two problems:
> a) If the user renames the DLL, GetModuleHandle() will not return its
>    handle any more.
> 
> b) If the name does not include a path and there is more than one
>    loaded module with the same base name and extension, you cannot
>    predict which module handle will be returned.
>    [MSDN Library]
> 
> 
> What can I do? Thanks in advance for any hints.
> 
> Regards,
>    Juergen
> 
> -- 
> Have you read a good program lately?
> 
> 

Hello there,


Perhaps you can simply send the path to a function in the dll from
the .exe file that loaded it.


Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu