You could try looking into how GAIM works, it is an Open Source program so you can just pop it open and look through the code. Or you could even go to #gaim on freenode or the mailing list and ask there.