How cool is this blog?

Did you know that you can drag and drop the boxes in the left or right and order them as you like?

Just move your mouse over the grey box until the cursor changes, and then drag the box to the new position as you like.

Give it a try and post a comment if you like it!

Twitter Button from twitbuttons.com

Blogroll

BlogCatalog



Showing posts with label threads. Show all posts

Ever wondered which program has a particular file or directory open? Now you can find out. Process Explorer shows you information about which handles and DLLs processes have opened or loaded.

The Process Explorer display consists of two sub-windows. The top window always shows a list of the currently active processes, including the names of their owning accounts, whereas the information displayed in the bottom window depends on the mode that Process Explorer is in: if it is in handle mode you'll see the handles that the process selected in the top window has opened; if Process Explorer is in DLL mode you'll see the DLLs and memory-mapped files that the process has loaded. Process Explorer also has a powerful search capability that will quickly show you which processes have particular handles opened or DLLs loaded.

The unique capabilities of Process Explorer make it useful for tracking down DLL-version problems or handle leaks, and provide insight into the way Windows and applications work.

Process Explorer works on Windows 9x/Me, Windows NT 4.0, Windows 2000, Windows XP, Server 2003, and 64-bit versions of Windows for x64 and IA64 processors, and Windows Vista.


Now here's a little extra trick you can do with the Process Explorer. You can find out what connections an application is using to communicate over LAN or Internet.

Have you ever wondered what IP address one of your YM or Skype friends has? Using Process Explorer you can now find out. Just open PE, find YM or Skype in the process list, double click on it and select the TCP/IP tab. You will now see all active connections for the process that use the TCP/IP protocol. Leave this window open and start chatting with your buddy. You will see the IP address appear (if it's not already in the list) and highlighted. While the communication is in progress, the highlight will be green, then red (communication stopped), and then it will not be highlighted anymore (might even disappear from the list).

You can use the same technique for Internet Explorer, Firefox, or any other application that creates TCP/IP connections.


Happy exploring your processes!



This is just a simple console application written in c++ that shows how to use multiple threads. Remember, it's just a SIMPLE application, don't expect too much from it. Use it as a demo or starting point.

[code]

#include <windows.h> //for thread
#include <stdio.h> // for print/read to/from console

typedef struct ThreadData {
int threadId;
} ThreadData, *PTHREADDATA;

void ListenForThreadEvent( LPVOID lpParam );

int main()
{
const int MAX_THREADS = 5;
HANDLE hThreadArray[MAX_THREADS];
PTHREADDATA pDataArray[MAX_THREADS];
DWORD dwThreadIdArray[MAX_THREADS];

for(int i=0; i<MAX_THREADS; i++)
{
pDataArray[i] = (PTHREADDATA) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(ThreadData));
if( pDataArray[i] == NULL )
{
ExitProcess(2);
}
pDataArray[i]->threadId = i;

hThreadArray[i] = CreateThread(
NULL, // default security attributes
0, // use default stack size
(LPTHREAD_START_ROUTINE) ListenForThreadEvent, // thread function name
pDataArray[i], // argument to thread function
0, // use default creation flags
&dwThreadIdArray[i]); // returns the thread identifier

if( hThreadArray[i] == NULL )
{
printf("CreateThread error: %d\n", GetLastError());
return 0;
}
}

WaitForMultipleObjects(MAX_THREADS, hThreadArray, TRUE, INFINITE);

for(int i=0; i<MAX_THREADS; i++)
{
CloseHandle(hThreadArray[i]);
if(pDataArray[i] != NULL)
{
HeapFree(GetProcessHeap(), 0, pDataArray[i]);
pDataArray[i] = NULL; // Ensure address is not reused.
}
}

// repeat until keypressed
char wait[5];
scanf(wait);

return 0;
}

void ListenForThreadEvent( LPVOID lpParam )
{
PTHREADDATA pDataArray;
pDataArray = (PTHREADDATA)lpParam;
int i = 0;
while(i < 10)
{
printf("thread %d step %d\n", pDataArray->threadId, i++);
}
}

[end code]

The result of running this application is:


NOTES:

  • If you start a new C++ empty project, you will probably have debugging disabled. To set it up and running, follow these steps:
    1) Goto Project->YourProjectName Properties (or right click on the project name in Solution Explorer and choose Properties)
    2) On the left expand "Configuration Properties"
    3) Expand "C/C++"
    4) On the left, Select "General"
    5) On the right, change "Debug Information Format" to "Program Database For Edit And Continue (/ZI)"
    5) On the left, Select "Optimization"
    6) On the right, change "Optimization" to "Disabled (/Od)"
    7) On the left, expand "Linker"
    8) On the left, select "Debugging"
    9) On the right, change "Generate Debug Info" to "Yes"
    10) Click ok
    11) Set your breakpoints
    12) Rebuild your application

  • This simple example is taken from a more documented but more complicated demo provided by Microsoft. I don't know why they need to usually complicate everything, but YOU MUST remember: Keep It Simple, Stupid! Anyway, the demo can be found here.



Subscribe to: Posts (Atom)

Feedjit

Bloglinker list