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.
LVL 8
gmayoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.