Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Application.ExeName in a DLL

Posted on 2004-11-01
Medium Priority
Last Modified: 2010-05-18
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.


Geoff M.
Question by:gmayo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 17

Accepted Solution

geobul earned 120 total points
ID: 12461989
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
LVL 17

Assisted Solution

by:Wim ten Brink
Wim ten Brink earned 80 total points
ID: 12462441
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
  NameBuffer: array[0..MAX_PATH] of char;
  Filename: string;
  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.

Expert Comment

ID: 12462451
If you use pacages, then the dll and exe will share the same forms object, and hence the same application object.

Author Comment

ID: 12462899
Okay, so what happens if the DLL is called by a C++ app? Will it work the same way?

Geoff M.
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12463377
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)...

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question