Solved

Application.ExeName in a DLL

Posted on 2004-11-01
812 Views
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.

Cheers

Geoff M.
0
Question by:gmayo
    5 Comments
     
    LVL 17

    Accepted Solution

    by:
    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
     
    LVL 17

    Assisted Solution

    by:Wim ten Brink
    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
     
    LVL 2

    Expert Comment

    by:Molando
    If you use pacages, then the dll and exe will share the same forms object, and hence the same application object.
    0
     
    LVL 8

    Author Comment

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

    Geoff M.
    0
     
    LVL 17

    Expert Comment

    by:Wim ten Brink
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Anonabox PRO Tor & VPN Router

    PRO is the most advanced way to fortify your privacy and online anonymity by layering the Tor network with VPN services. Use both together or separately, and without needing to download software onto your devices.

    Suggested Solutions

    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    This video Micro Tutorial is the first in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles al…
    This video discusses moving either the default database or any database to a new volume.

    875 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now