why dont you take a look to this?
is the same question i did 2 years ago. hehe.
and i think this is probably what you have been waiting for.

http://cboard.cprogramming.com/showthread.php?t=85752