Solved

Get name of DLL Caller ?

Posted on 2004-10-11
5
835 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
ID: 12274700
SysUtils.GetModuleName(0) does that just fine :)
0
 
LVL 20

Accepted Solution

by:
Madshi earned 250 total points
ID: 12274720
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
ID: 12274727
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
ID: 12274735
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
ID: 12277418
thanks madshi
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

813 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

10 Experts available now in Live!

Get 1:1 Help Now