• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 922
  • Last Modified:

Application.ExeName in a DLL

Can I just confirm that calling Application.ExeName WILL return the calling application's name, rather than the DLL? This is for 95/98/ME/XP/2k - if any of these work differently, please say so. This is something I want, I don't need the DLL's name.

Cheers

Geoff M.
0
gmayo
Asked:
gmayo
2 Solutions
 
geobulCommented:
Yes, I think. You'll have to add 'Forms' to the uses clause of the DLL unit, of course, because Application is defined there. The same result for either static or dynamic linking.

Regards, Geo
0
 
Wim ten BrinkSelf-employed developerCommented:
Application.Exename will call ParamStr(0). If you call the DLL from a Delphi application then this will return the name of the executable. However, this isn't always guarantueed! Normally you would use
var
  NameBuffer: array[0..MAX_PATH] of char;
  Filename: string;
begin
  GetModuleFileName(HInstance, NameBuffer, MAX_PATH);
  Filename := NameBuffer;

but this will return the DLL name, not the executable name. But if you use MainInstance instead of HInstance then you use the instance of the executable. Thus:
  GetModuleFileName(MainInstance, NameBuffer, MAX_PATH);
should return the executable name in the NameBuffer variable.

But in general you could also use ParamStr(0) in almost all cases. There might be some special occasions where it won't work but those are quite rare.
0
 
MolandoCommented:
If you use pacages, then the dll and exe will share the same forms object, and hence the same application object.
0
 
gmayoAuthor Commented:
Okay, so what happens if the DLL is called by a C++ app? Will it work the same way?

Geoff M.
0
 
Wim ten BrinkSelf-employed developerCommented:
Geoff, it should work and in general it will work. The only problems I've discovered in the past were COM objects inside a DLL that took rundll.exe as executable name instead of the executable that was really calling them. And I once had a problem with some scripting engine that allowed you to call methods from a DLL but this engine would link the wrong executable to the DLL. But in general, a plain, simple DLL should work just fine with ParamStr(0)...
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now