[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Get name of DLL Caller ?

Posted on 2004-10-11
5
Medium Priority
?
865 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
[X]
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
  • 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 1000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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 you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
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 …
Suggested Courses

649 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