Where is my DLL?
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 ...
)
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
, 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?
|
Not Categorized, Please Help
|
|