Question

Un fichier exe de Windows a accès à la chaîne de commande qui l'invoque, notamment son chemin d'accès et nom de fichier.par exemple. C:\MyApp\MyApp.exe --help.

Mais ce n'est pas pour une dll appelé par l'intermédiaire de LoadLibrary.Quelqu'un sait-il d'un moyen pour une dll pour savoir ce que son chemin d'accès et nom de fichier est?

Plus précisément, je suis intéressé par un Delphi solution, mais je pense que la réponse serait à peu près la même pour toutes les langues.

Était-ce utile?

La solution

Je pense que vous êtes à la recherche pour 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;

Non testé, cependant, été un certain temps depuis que j'ai travaillé avec Delphi :)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top