A Win32 Network Crawler

by Jawed Karim 





Listing One

HANDLE hRoot = GetNetworkHandle (NULL);

RecurseNetworkLevels (hRoot);

WNetCloseEnum (hRoot);



Listing Two

RecurseNetworkLevels (HANDLE handle)

{

    NETRESOURCE netres[NUM_RES];

int numEntries = GetNetworkInfo (handle, netres, NUM_RES);

for (int i = 0; i < NUM_RES; i++)

{

    PrintResource (netres[i]);

    HANDLE tmp = GetNetworkHandle (&netres[i])

    RecurseNetworkLevels (tmp);

}

}



Listing Three

// passing Voyeur's view's window handle to the thread.

// (called from CVoyeurView)

::AfxBeginThread (thread_func, (void *)m_hWnd);

// reconstructing the Voyeur's view pointer from its window handle.

unsigned int thread_func (void *arg)

{

    HWND hwnd = (HWND)arg;

    CWnd *pWnd = CWnd::FromHandle (hwnd);

    CVoyeurView *pvView = (CVoyeurView *)pWnd;

    // proceed to use pvView ...

}



















1



