Ad
Can A Windows Dll Retrieve Its Own Filename?
A Windows process created from an exe file has access to the command string which invoked it, including its file's path and filename. eg. C:\MyApp\MyApp.exe --help
.
But this is not so for a dll invoked via LoadLibrary
. Does anyone know of a way for a function loaded via dll to find out what its path and filename is?
Specifically I'm interested in a Delphi solution, but I suspect that the answer would be pretty much the same for any language.
Ad
Answer
I think you're looking for GetModuleFileName.
http://www.swissdelphicenter.ch/torry/showcode.php?id=143:
{
If you are working on a DLL and are interested in the filename of the
DLL rather than the filename of the application, then you can use this function:
}
function GetModuleName: string;
var
szFileName: array[0..MAX_PATH] of Char;
begin
FillChar(szFileName, SizeOf(szFileName), #0);
GetModuleFileName(hInstance, szFileName, MAX_PATH);
Result := szFileName;
end;
Untested though, been some time since I worked with Delphi :)
Ad
source: stackoverflow.com
Related Questions
- → React-Starterify Project on Windows computer, babel not working
- → Setting environment variables in package.json scripts under Windows
- → React component for "rectangle selection"
- → How Can I install OctoberCMS with PHP Version 5.x?
- → How does this JavaScript open Windows Settings in Firefox?
- → Reconfigure Homestead vagrant box after issue
- → When installing just PHP on Windows, all php extensions are commented out by default?
- → Bootstrap collapse and modal windows JS
- → Laravel uploading file Unable to write in directory
- → Bootstrap modal window not showing
- → Angular-drag-and-drop-lists: Inputs with draggable property causing unintended behavior in IE
- → Using gulp with Laravel Elixir - disable tray icon messages?
- → .gitignore the database file in laravel
Ad