Solved

Get name of DLL Caller ?

Posted on 2004-10-11
5
823 Views
Last Modified: 2010-04-04
In global hook ,how can i get the name of the file exe,which called file dll?
code: results of paramstr(0)  in file dll are not same because activate window changed too.
example :
project.exe calls a.dll ,the caller is project1.exe. when a.dll loading,it always shows [messagebox(paramstr(0))] the caller is  "c:\my\project.exe" but if we set focus to yahoo messenger it will show "c:\program files\yahoo\messenger\ypager.exe"

So how can we get the filename of the DLL caller only everytime (project.exe)?

by the way,How can the file dll get  the filename of itself?

(i means a.dll when loading will showmessage the name of itself like c:\....\a.dll )
0
Comment
Question by:lehongwang
  • 3
5 Comments
 
LVL 12

Expert Comment

by:Lee_Nover
Comment Utility
SysUtils.GetModuleName(0) does that just fine :)
0
 
LVL 20

Accepted Solution

by:
Madshi earned 250 total points
Comment Utility
You can't get the name of the exe which started the global hook - if that is what you need. You can get the name of the exe in which the current copy of your dll is loaded. That's exactly what "ParamStr(0)" does. Probably you know that a copy of your dll is loaded into every running GUI process?

Asking the name of the dll itself is easy. Just use GetModuleFileName(HInstance, ...).
0
 
LVL 12

Expert Comment

by:Lee_Nover
Comment Utility
oh .. my bad .. same thing
although it's very weird .. but since you're in a hook dll it's logical that the topmost window has the input
when do you want to know the modulename ?
anyway you can create a global var and store the name there - every process get's it's own copy of the variable
so in the dllmain entry proc set the global var .. should work :)


// in the dll's .dpr file - ModName can be declared anywhere

var ModName: string = '';

function DoInit: Integer; stdcall;
begin
  ModName:=SysUtils.GetModuleName(0);
end;

procedure EntryPointProc(Reason: Integer);
begin
  case Reason of
    DLL_PROCESS_ATTACH: DoInit;
  end;
end;

begin
  DllProc:=@EntryPointProc;
  EntryPointProc(DLL_PROCESS_ATTACH);
end.
0
 
LVL 12

Expert Comment

by:Lee_Nover
Comment Utility
or shorter:

var ModName: string = '';
begin
  ModName:=SysUtils.GetModuleName(0);
end.


even shorter:

in any unit:

initialization
  ModName:=SysUtils.GetModuleName(0);
end.
0
 

Author Comment

by:lehongwang
Comment Utility
thanks madshi
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

16 Experts available now in Live!

Get 1:1 Help Now