Pergunta

Um arquivo exe do Windows tem acesso à string de comando que o invocou, incluindo seu caminho e nome de arquivo.por exemplo. C:\MyApp\MyApp.exe --help.

Mas isso não é assim para uma dll invocada via LoadLibrary.Alguém conhece uma maneira de uma dll descobrir qual é seu caminho e nome de arquivo?

Especificamente, estou interessado em uma solução Delphi, mas suspeito que a resposta seria praticamente a mesma para qualquer idioma.

Foi útil?

Solução

Acho que você está procurando 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;

Não testado, porém, já faz algum tempo que não trabalho com Delphi :)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top