예제 #1
0
        internal Protocol(ref PROTOCOLDESCRIPTOR descriptor)
        {
            if (descriptor.Name == IntPtr.Zero)
                throw new ArgumentException();

            this.name = Translate.ToString(descriptor.Name, StringEncoding.Ansi);
            this.type = (ProtocolType)descriptor.Type;
        }
예제 #2
0
        internal void Register()
        {
            if (Registered)
                throw new InvalidOperationException();

            PROTOCOLDESCRIPTOR descriptor = new PROTOCOLDESCRIPTOR(Name, Type);
            UnmanagedStructHandle<PROTOCOLDESCRIPTOR> nativeHandle = UnmanagedStructHandle<PROTOCOLDESCRIPTOR>.Empty;

            try
            {
                nativeHandle = new UnmanagedStructHandle<PROTOCOLDESCRIPTOR>(ref descriptor);
                int result = Context.CallService(MirandaServices.MS_PROTO_REGISTERMODULE, UIntPtr.Zero, nativeHandle.IntPtr);

                if (result != 0)
                    throw new MirandaException(String.Format(TextResources.ExceptionMsg_Formatable2_MirandaServiceReturnedFailure, result.ToString()));

                this.nativeDescriptor = descriptor;
                Registered = true;
            }
            finally
            {
                nativeHandle.Free();
            }
        }