A++ Process Routines Library 1.3 (niflib.dll) Readme file. 7.11.2000
(Author Andrey Nefedov)


Registration

You can register the product Online or via Voice, Fax, or Postal Mail.
For details see:

Regsoft 1 or Regsoft 2

If you have any questions about registration, send them to:

eskylex@usa.net

Note: Only registered users can distribute this library with their products. Illegal distribution and use of this library will be traced and persecuted to the maximum extent under law.
________________________________

Introduction

This library gives you a set powerful tools to control and manipulate any application routines of Microsoft Windows. With this library, you can get a window by its exe-path, process or caption. Also, you can get any process by its child thread or exe-path, and an exe-path by its process. You can enumerate processes and threads, as well as the threads and windows of a process. Furthermore, you can absolutely correctly terminate any application (process), including the application's toolbars, and indicator programs.
In addition, the library contains useful functions that can make any process invisible to the task switcher.

The next release of the library will include additional process-enumerating functions, process tracing functions, window management functions, and the possibility to obtain the selected text from any application.

Registered developers will get a right to distibute the library with their products as well as free unlimited support, free updates and source code.

__________________________________

Technical Details:

The functions of this library provide easy access to application
routines of Microsoft Windows. The library works on Windows 95/98
(should also work with Windows NT/2000).

1. Main

Simplified application scheme:
Process
| |Window
---Thread---|Window
| |...
|
| |Window
---Thread---|Window
| |...
|
...

Process has: Exe-path, Threads, Windows, Id, Handle
Thread has: Windows, Id, Owner process
Window has: Owner process, Caption, Exe-path.

2. Installation

Copy niflib.dll into the application directory or in the Windows System directory.

For Delphi developers:

Copy interface unit nifintr.dcu into Delphi\LIB directory. To see the source, also copy
nifintr.pas.

-----------
Import example for Delphi (NOT needed if NifIntr unit is in the Uses list.):

In interface var section:

function GetPidByExePath(path:pchar):dword;stdcall;

In implementation:

function GetPidByExePath; external 'niflib.dll' index 6;

-----------

3. List of functions:

Note: if the function is not succesful, it returns 0 for handles and ids and an empty string
for Pchar. If Bool function returns False, it means that there was an unexpected exit.

To obtain PID of the window use getwindowthreadprocessid function.
Do not forget about getcurrentprocessid function.

---

GetWndByExe(path:pchar;host:hwnd):hwnd;

Obtains a handle to the window whose process has an exe-path equal to the path varibale.

---

GetWndByCapt(capt:pchar;host:hwnd):hwnd;

Obtains the window's handle by its caption.

---

GetWindowExe(window:hwnd):pchar;

Obtains the window's exe-path.

---

GetProcessList(
var idlist: array of dword;
var pathlist:array of string;
var cnt:integer):bool;

Makes a system snapshot and fills the idlist with process ids and the pathlist with
their exe-paths. cnt variable gets the count of processes.

---

GetThreadList(
var idlist: array of dword;
var parentidslist: array of dword;
var cnt:integer):bool;

Makes a system snapshot and fills the idlist with thread ids and the parentidslist with
their parent's identifiers. cnt variable gets the count of threads.

---

GetPidByExePath(path:pchar):dword;

Returns the process identifier whose exe-path is equal to the path variable.

---

GetParentPid(threadid:dword):dword;

Returns the process identifier that is the parent for the thread with id equal to
the threadid variable.

---

GetProcessThreadID(pid:dword):dword;

Obtains identifier of the first thread of the process whose identifier is equal to PID.
To enumerate use EnumThreads function.

---

KillApplicationByExe(exe:pchar;caller:hwnd):bool;

Closes EVERY application with the corresponding exe-path.

Mechanism:
First, every application's window closes. Second, every application's thread closes.
Then the process terminates by the TerminateProcess function. As a rule, after the first step,
the application is already terminated.The mechanism takes into account that the application
can have notification icons and can be an application toolbar.

---

GetWndByPid(pid:dword;host:hwnd):hwnd;

Obtains the handle of the first window of a process with Pid id.
To enumerate use EnumPrWnds function.

---

KillApplicationByPid(pid:dword;caller:hwnd):bool;

Closes the application whose process id is pid. The same mechanism is used.

---

EnumPrThreads(pid:dword;callb:EnumPrThreadsCallback):bool;

Passes the ids of all threads of the process with Pid id to the callback function

function CallBack(Threadid:dword):bool;

Until it returns true or all threads enumerated.

---

EnumPrWnds(pid:dword;callb:EnumPrWndsCallback;host:hwnd):bool;

Passes the handles of the windows belonging to the pid-process to the callback function

function callback(Window:hwnd):bool;

Until it returns true or all windows enumerated. It does not takes into account
the child windows.

---

KillProcessByThreads(pid:dword):bool;

Quits all threads belonging to a pid-process.

---

function MakeProcessInvisible(pid:dword):dword;

Makes pid process invisble for the task switcher.

---

function UnMakeProcessInvisible(pid:dword):dword;

Makes pid process visible for the task switcher.

---

function GetMainParent(window:hwnd):hwnd;

Returns handle of main parent window. Returns 0 to desktop.

---

Strings management functions:

comparestr(s1,s2:pchar):bool;- Compares strings. Not case-sensitive.

function mypos(s1,s2:pchar):integer; POS function analog. Not case-sensitive.

These functions also work with the Russian versions of MS Windows.

---
version 1.3:
---

procedure BuildWndTree(mainwindow:hwnd;Clb:BuildWndTreeCallback);

Passes the handles (and the level) of the windows belonging to the MainWindow to the
callback function

function (Window:hwnd;level:integer):bool;

Until it returns true or all windows enumerated. You can build child windows tree,
and find ANY window!

---
procedure EnumExePids(path:pchar;Clb:EnumExePidsCallback);

Passes the PIDs of all processes with "path" exepath to the callback function

function (Window:hwnd;level:integer):bool;

Until it returns true or all processes enumerated.

----------------------------------------------------------

Export table:

CompareStr index 1,
GetWndByCapt index 2,
GetProcessThreadID index 3,
GetProcessList index 4,
GetThreadList index 5,
GetPIDByExePath index 6,
GetExePathByPID index 7,
GetParentPID index 8,
GetWndByExe index 9,
GetWindowExe index 10,
MyPos index 11,
KillApplicationByExe index 12,
GetWndByPid index 13,
KillApplicationByPid index 14,
EnumPrThreads index 15,
EnumPrWnds index 16,
KillProcessByThreads index 17,
MakeProcessInvisible index 18,
UnMakeProcessInvisible index 19,
GetMainParent index 20;

----------------------------------------------------------

"Windows" - is a registered trademark of Microsoft corp.