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



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.



[quote]
Have ever laid your eyes on a cool scene from a movie? Something that you would want to capture as an image and put it as your desktop, avatar, etc. ? So what do you do when you want that done?

"Well", says the unexperienced but still Windows familiar person, "that's an easy task! You start playing the movie with some video player and the press the <> button. Open up <> and paste the contents of the clipboard and save it in whatever format you want".

Those of you who watched Cartoon Network and their cute cartoon called "2 Stupid Dogs" will recognize this quote:

Quote:
Now, isn't that cute? ... BUT IS WRONG!!!!
[end quote]

This is just the starting part of a forum post I once posted on a tips and tricks wannabe forum. You can find the post here:
http://www.i-hate-microsoft.com/capture-a-frame
-of-a-movie-in-media-player-t3.html

But blogging is more fun :) And now I have a solution for it so "it's tiiiime to blllogg it".

The problem: You are playing a news movie using Media Payler. You see your neighbor's face and want to take a screenshot so you can make fun of his haircut. You pause the movie, press the print screen button (Prnt Scrn key, with or without the combination with ALT), you open paint, paste the screenshot and save it as a JPEG formated image. And what do you get? This:


(Please note this is the actual screen shot I saved using MS Paint. You can test it yourself by following the steps described above).

What you actually expected to see, that is the content of the movie, is missing. Why? Because of the way movies are played in Windows. That is, for hardware acceleration purposes, the movie part is just a "layer overplayed over the player window" ( :D ). Having said this, when you take a screen shot of the player, you only get the player window and some pointer to the memory location where the video layer is located. When you paste that in MS Paint, you see (kind of) both layers, but if you close Media Player, only the player image remains (because the video layer pointer points to nothing).

Solution? Go to: Control Panel->Display->Settings tab->Advanced->Troubleshoot tab and drag the Hardware acceleration slider to None. Save the settings and try the capture again:


That's it! "Keep it safe and smooth people!"

NOTE: While this setting has benefits, it also has some drawbacks. Play with it at your own risk and read the note offered by MS on the Troubleshoot tab before proceeding. I did this once and I lost my desktop image. That's not a big deal, but who knows what else can happen. Disabling hardware acceleration also means less detail in graphics applications. Bottom line - handle with care and knowledge. If you are unsure, just leave it as is and use a smart screen capture tool.



I had a little problem with my wireless network card. Every few minutes (sometimes 10-15 minutes, sometimes 1-2 minutes,...) the connection was dropping, and then it went up again in just a few seconds. Well, it doesn't sound too annoying, but believe me, it can get on anyone's nerves... It got on mine at least (after a couple of months of disconnect, connect, disconnect, "Wireless networks are in range", connect, disconnect, ... ... ... ).

So I did a little searching on Yahoo and found a few (ok, maybe a lot) of people having the same problem I have. The OS did not seem to have much to do with it, as I found people complaining about Debian and Ubuntu also. Still, the solutions presented were typical for forums nowadays: "buy new wi-fi card", "your router sucks, buy new one"...

So I started reading a Linux forum with some people asking for various config settings and debug tools to be posted from the "victim" machine. It went nice, I kinda understood what they were saying. And then somebody posts a log with a bunch of things I don't understand, the next post they say:

[quote]

------- Comment #24 From Rodrigo Barbosa 2006-04-28 21:34:50 -------
Disabling the storming protection makes the symptons
completly disapear. If that is really solving
the problem itself or not, I can't say, but even video
streaming works flawlessly over the wifi network now.
------- Comment #25 From Erik Slagter 2006-07-05 05:21:38 -------
Using latest ipw2200 and ieee802.3 and using module parameter
roaming=0, no more problems.
------- Comment #26 From Zhu Yi 2006-07-23 23:35:02 -------
mark as resolved according to comment #25 
[end quote]

(http://www.intellinuxwireless.org/bugzilla/show_bug.cgi?id=813#c24)

And by that you mean exactly ... what? What ... a waste of time, cause' I did not understand a thing.

So I started over with my search and, eventually, someone wrote the magic words: "power saver mode". Ding!

What's the real problem? It seems that if you set your wi-fi adapter in power save mode = enabled, which basically means it will disconnect if you are not using the connection in order to save power, it will do just that - disconnect when you are not using the connection... Now you're probably arguing that (if this also happened to you as it did for me) you were browsing the net and then, suddenly got disconnected, no way you were not making traffic, even less not using the connection. LOL

Solution? Go to: Control Panel->System->Hardware tab->Device manager->Network adapters, find our wi-fi adapter and right click->Properties. In the Advanced tab you will see a list of item, and a box for the value of the selected item. Change "Power Save Mode" to disabled. ( I also changed "Minimum Power Consumption" to disabled since I only use AC power supply to save my battery life. I noticed after the change that I get a lot more low signal indications then previously - 2 red lines out of 4 - which might mean that the signal being too low and the minimum power consumption enabled, my wi-fi just disconnected in order to avoid using more power to amplify the signal...hmmm). Once this done, your network will be disconnected again and then reconnected, but this time it stays connected.

NOTE: If you are using your battery, you should be careful about the power consumption caused by this switch. It might drain a little more than you are expecting so take good care. You can always enable the settings while using battery, and then disable it when AC powered.

I don't know about all of you, but I usually keep track of all my user/password information. How? Usually I save them in Firefox (web based accounts that is) and in Total Commander (ftp accounts). Dough, what did you think, that keep a diary of all my passwords? Dude, if you get to that point you just need to "format Internet:" and get a break!!!

So, people at Firefox (good Firefox, good :) ) imagined that people like me exist, so they added a *cool* feature to the Tools->Options->Security tab called "Show passwords". And it works great. Yeah, sure, if your desk neighbor gets 2 minutes to your PC, you can say "Bye-bye privacy". I just know that I work with great people in the office that would never ever try that...

Ok, that solves the "forgot password" for web accounts. But what about FTP accounts or any other password (remote desktop, etc.)?

Well, I found a cool and very easy to build tool that you just press a button and it shows you the password. Nice! Here is the link: http://www.rekenwonder.com/revealer.htm

The best part is that they also provide the source code which is just a couple of lines (see below). So, the next time you save your password, keep in mind that somebody might find it and expose all your pics and flicks to the community...

BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam);
BOOL CALLBACK EnumWindowsProc2(HWND hwnd,LPARAM lParam);

LRESULT CALLBACK MainWndProc(HWND hWndMain,UINT Msg,
UINT wParam,LONG lParam)
{
switch(Msg) {
case WM_COMMAND:
if(HIWORD(wParam)==BN_CLICKED)
// call every main window
EnumWindows(EnumWindowsProc,0);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0L;
}
return DefWindowProc(hWndMain,Msg,wParam,lParam);
}

BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
// call every child window (to find edit boxes)
EnumChildWindows(hwnd,EnumWindowsProc2,lParam);
return TRUE;
}

BOOL CALLBACK EnumWindowsProc2(HWND hwnd,LPARAM)
{
// reveal the password
::SendMessage(hwnd,EM_SETPASSWORDCHAR,0,0);
InvalidateRect(hwnd,NULL,FALSE);
return TRUE;
}

The first trick I want to speak about is related to Google. Long live Google! Imagine how fun it is to ask Google how to tipGoogle :)

Well, I did that and found some cool tricks. If you're hoping to crash their engine or mess something up...nah, this isn't the case. Instead, you might just find an easier way to do searches or improve your search result.


Trick 1 - Filter your search to find only files that can be downloaded

Enter the following as a search phrase in Google (without the <<>>): <<"intitle:index of" nero>>. So what do you get? Just a list of sites that have the keyword (in our case <>) among their file names. You can use this with any combination of words:

"intitle:index of" bocelli mp3 -> will search for mp3 songs by Andrea Bocelli
"intitle:index of" bud light avi -> you get a lot of Bud Light commercials


Trick 2 - Web cams

Have you ever wanted to spy on people? Well, this is your chance. Ask Google to search for:

inurl:/view/index.shtml

and you will get a list with all the folks out there that have their camera brodcasting on the Internet. Why do they do that? :| ... ask them...


Trick 3 - I'm Feeling lucky

If you're feeling lucky with Google, you might get a lot of fun stuff. Just enter the keywords and press the "I'm feeling lucky" button (instead of the search one):

google l33t
google gothic
google chesse
google easter egg
elgoog
answer to life, the universe and everything else
find Chuck Norris


Trick 4 - THIS IS A REAL SECURITY PROBLEM (please use it cautiously)

“# -FrontPage-” inurl:service.pwd

This search will show you passwords for sites that are not really secured


Trick 5 - Pretend to be Googlebot

Did you ever search for something (most likely a file), and you got the result, but when you tried to access it, you were taken to the login page of that site? So how does Google know about that file? In order to get more traffic and more hits in Google, some sites allow access to their protected zones for the Googlebot (the crawler that "eats" all the keywords from every site). So it seems that if you act as being Googlebot, you should be able to access more resources than usual.

To do just that, open registry editor (Start->Run->regedit *press enter*) and modify this key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent

(or you can save the text below in a google.reg file, then double click on it and choose Yes when asked)

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent]
@="Googlebot/2.1"
"Compatible"="+http://www.googlebot.com/bot.html"

Now, when you will browse the Internet, all the pages will think you are the Googlebot, so they will allow more access. Have fun.

To put it back as it was, do the same with this code:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent]
@="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"



Trick 6 - Search for PDF or DOC files

Use <> after the keywords you enter and you will get only PDF results for your search:

shackespeare filetype:pdf

Other tricks:


intext:"UAA (MSB)" Lexmark -ext -> shows a list of printers (not sure what to do with them)
inurl:"viewframe?mode=refresh"



Enjoy your Google experience and please place comments if you find other tricks.

Subscribe to: Posts (Atom)

Feedjit

Bloglinker list