Extern "C" Long export _ stdcall getrootitem (long thwnd, char * filestr ){
Tvitem TVI, * _ TVI;
Char * _ item;
Char item [256];
Unsigned long PID;
Handle process;
Long ret = (long) (ctreectrl *) cwnd: fromhandle (hwnd) thwnd)-> getrootitem ();
If (RET ){
/*
Getwindowthreadprocessid
Description
Gets a process and thread identifier associated with a specified window.
Return Value
Long, the identifier of the thread that owns the window
Parameter table
Parameter type and description
Lpdwprocessid long: Specifies a variable to load the identifier of a process that owns the window.
Hwnd long, specify the window handle
*/
Getwindowthreadprocessid (hwnd) thwnd, & pid );
// Open the process with all Permissions
Process = OpenProcess (process_vm_operation | process_vm_read | process_vm_write | process_query_information, false, pid );
// Allocate process-level virtual memory space to _ LVI and _ item
_ TVI = (tvitem *) virtualallocex (process, null, sizeof (tvitem), mem_commit, page_readwrite );
_ Item = (char *) virtualallocex (process, null, 256, mem_commit, page_readwrite );
TVI. cchtexmax = 256;
TVI. hitem = (htreeitem) ret;
TVI. Mask = tvif_text;
TVI. psztext = _ item;
// Write _ LVI TO THE PROCESS
Writeprocessmemory (process, _ TVI, & TVI, sizeof (tvitem), null );
// Send the message to get the data
: Sendmessage (hwnd) thwnd, tvm_getitem, 0, (lparam) _ TVI );
// Read data from the process
Readprocessmemory (process, _ item, item, 256, null );
// Copy data
Memcpy (filestr, item, 256 );
// Free memory
Virtualfreeex (process, _ TVI, 0, mem_release );
Virtualfreeex (process, _ item, 0, mem_release );
}
Return ret;
}
Extern "C" Long export _ stdcall getnextitem (hwnd thwnd, long next, char * filestr ){
Tvitem TVI, * _ TVI;
Char item [256];
Char * _ item;
Unsigned long PID;
Handle process;
Long ret = (long) (ctreectrl *) cwnd: fromhandle (thwnd)-> getnextsiblingitem (htreeitem) Next );
If (RET ){
Getwindowthreadprocessid (thwnd, & pid );
Process = OpenProcess (process_vm_operation | process_vm_read | process_vm_write | process_query_information, false, pid );
_ TVI = (tvitem *) virtualallocex (process, null, sizeof (tvitem), mem_commit, page_readwrite );
_ Item = (char *) virtualallocex (process, null, 256, mem_commit, page_readwrite );
TVI. cchtexmax = 256;
TVI. hitem = (htreeitem) ret;
TVI. Mask = tvif_text;
TVI. psztext = _ item;
Writeprocessmemory (process, _ TVI, & TVI, sizeof (tvitem), null );
: Sendmessage (thwnd, tvm_getitem, 0, (lparam) _ TVI );
Readprocessmemory (process, _ item, item, 256, null );
Memcpy (filestr, item, 256 );
Virtualfreeex (process, _ TVI, 0, mem_release );
Virtualfreeex (process, _ item, 0, mem_release );
}
Return ret;
}
The above functions can be called in VB and Vc in the DLL. However, if the machine does not have VC installed, mfc42d. dll and msvcrtd. dll are required to be called in VB.