Esempio n. 1
0
        /// <summary>
        /// Load method will be called on plugin load.
        /// </summary>
        protected override void Load()
        {
            this.CreateServiceFunction("TestPlug/MenuCommand",
                menuCommand);

            var mi = new CListMenuItem();
            mi.position = -0x7FFFFFFF;
            mi.flags = 0;
            // TODO: Load icon:
            // mi.hIcon = LoadSkinnedIcon(SKINICON_OTHER_MIRANDA);
            mi.name = "&Test Plugin...";
            mi.service = "TestPlug/MenuCommand";

            // You can use raw IntPtr instead of AutoPtr here, but then do not
            // forget to call Marshal.FreeHGlobal to prevent memory leaks.
            using (var pClistMenuItem = new AutoPtr(
                Marshal.AllocHGlobal(Marshal.SizeOf(typeof (CListMenuItem)))))
            {
                Marshal.StructureToPtr(mi, pClistMenuItem, false);
                this.CallService("CList/AddMainMenuItem", IntPtr.Zero,
                    pClistMenuItem);
            }
        }
Esempio n. 2
0
        private int EventAdded(IntPtr wParam, IntPtr lParam)
        {
            IntPtr hContact = wParam;
            IntPtr hDBEvent = lParam;

            int blobSize = this.CallService("DB/Event/GetBlobSize",
                hDBEvent, IntPtr.Zero).ToInt32();

            using (var pBlob = new AutoPtr(Marshal.AllocHGlobal(blobSize)))
            using (var pDBEventInfo = new AutoPtr(
                Marshal.AllocHGlobal(Marshal.SizeOf(typeof (DBEventInfo)))))
            {
                var eventInfo = new DBEventInfo();
                eventInfo.pBlob = pBlob;
                eventInfo.cbBlob = (uint)blobSize;

                Marshal.StructureToPtr(eventInfo, pDBEventInfo, false);
                this.CallService("DB/Event/Get", hDBEvent, pDBEventInfo);

                eventInfo = (DBEventInfo)Marshal.PtrToStructure(pDBEventInfo,
                    typeof (DBEventInfo));

                if (eventInfo.eventType == DBEventInfo.EVENTTYPE_MESSAGE)
                {
                    using (var pDBEventGetText = new AutoPtr(
                        Marshal.AllocHGlobal(Marshal.SizeOf(
                            typeof (DBEventGetText)))))
                    {
                        var getText = new DBEventGetText();
                        getText.dbei = pDBEventInfo;
                        getText.datatype = Utils.DBVT_ASCIIZ;
                        getText.codepage = 1251;

                        Marshal.StructureToPtr(getText, pDBEventGetText,
                            false);

                        IntPtr pString = this.CallService(
                            "DB/Event/GetText", IntPtr.Zero, pDBEventGetText);
                        string message = Marshal.PtrToStringAnsi(pString);

                        mmi.mmi_free(pString);

                        var contact = new Contact(hContact);

                        DateTime eventTime = new DateTime(1970, 1, 1).
                            AddSeconds(eventInfo.timestamp).ToUniversalTime();
                        if ((eventInfo.flags & DBEventInfo.DBEF_SENT) != 0)
                        {
                            if (MessageSentEvent != null)
                                MessageSentEvent(contact, eventTime, message);
                        }
                        else
                        {
                            if (MessageReceivedEvent != null)
                                MessageReceivedEvent(contact, eventTime,
                                    message);
                        }
                    }
                }
            }

            return 0;
        }