你在mainframe得OnCreateClient函数中调用这些代码。
http://www.cnblogs.com/johnpher/archive/2011/03/05/2570712.html
你上面的代码运行有什么问题吗?