示例#1
0
        public virtual void Connect()
        {
            lock (locker)
            {
                // XSpeed多次连接出问题,发现会生成多次
                if (proxy == null)
                {
                    proxy = new Proxy(_Path1);
                }

                Handle = proxy.XRequest((byte)RequestType.Create, IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, 0);

                Register(_Queue.Handle);

                _Queue.Register(Marshal.GetFunctionPointerForDelegate(_XRespone));
                // 启动队列循环
                _Queue.Connect();

                IntPtr ServerIntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ServerInfoField)));
                Marshal.StructureToPtr(Server, ServerIntPtr, false);

                IntPtr UserIntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(UserInfoField)));
                Marshal.StructureToPtr(User, UserIntPtr, false);

                // 进行连接
                proxy.XRequest((byte)RequestType.Connect, Handle, IntPtr.Zero, 0, 0, ServerIntPtr, 0, UserIntPtr, 0, Marshal.StringToHGlobalAnsi(Path.GetTempPath()), 0);

                Marshal.FreeHGlobal(ServerIntPtr);
                Marshal.FreeHGlobal(UserIntPtr);
            }
        }