Exemplo n.º 1
0
 protected virtual void OnPost(MONMSGSTRUCT mon)
 {
 }
Exemplo n.º 2
0
 protected virtual void OnSend(MONMSGSTRUCT mon)
 {
 }
Exemplo n.º 3
0
        private IntPtr OnDdeCallback(int uType, ConversionFormat uFmt, IntPtr hConv, IntPtr hsz1, IntPtr hsz2, IntPtr hData, uint dwData1, uint dwData2)
        {
            // Create a new transaction object that will be dispatched to a DdemlClient, DdemlServer, or ITransactionFilter.
            // Dispatch the transaction.
            switch (uType)
            {
            case Ddeml.XTYP_MONITOR:
                switch (dwData2)
                {
                case Ddeml.MF_CALLBACKS:
                {
                    // Get the MONCBSTRUCT object.
                    int         length = 0;
                    IntPtr      phData = Ddeml.DdeAccessData(hData, ref length);
                    MONCBSTRUCT mon    = (MONCBSTRUCT)Marshal.PtrToStructure(phData, typeof(MONCBSTRUCT));
                    Ddeml.DdeUnaccessData(hData);
                    OnCallback(mon);
                    return(IntPtr.Zero);
                }

                case Ddeml.MF_CONV:
                {
                    // Get the MONCONVSTRUCT object.
                    int           length = 0;
                    IntPtr        phData = Ddeml.DdeAccessData(hData, ref length);
                    MONCONVSTRUCT mon    = (MONCONVSTRUCT)Marshal.PtrToStructure(phData, typeof(MONCONVSTRUCT));
                    Ddeml.DdeUnaccessData(hData);
                    OnConversation(mon);
                    return(IntPtr.Zero);
                }

                case Ddeml.MF_ERRORS:
                {
                    // Get the MONERRSTRUCT object.
                    int          length = 0;
                    IntPtr       phData = Ddeml.DdeAccessData(hData, ref length);
                    MONERRSTRUCT mon    = (MONERRSTRUCT)Marshal.PtrToStructure(phData, typeof(MONERRSTRUCT));
                    Ddeml.DdeUnaccessData(hData);
                    OnError(mon);
                    return(IntPtr.Zero);
                }

                case Ddeml.MF_HSZ_INFO:
                {
                    // Get the MONHSZSTRUCT object.
                    int          length = 0;
                    IntPtr       phData = Ddeml.DdeAccessData(hData, ref length);
                    MONHSZSTRUCT mon    = (MONHSZSTRUCT)Marshal.PtrToStructure(phData, typeof(MONHSZSTRUCT));
                    Ddeml.DdeUnaccessData(hData);
                    OnString(mon);
                    return(IntPtr.Zero);
                }

                case Ddeml.MF_LINKS:
                {
                    // Get the MONLINKSTRUCT object.
                    int           length = 0;
                    IntPtr        phData = Ddeml.DdeAccessData(hData, ref length);
                    MONLINKSTRUCT mon    = (MONLINKSTRUCT)Marshal.PtrToStructure(phData, typeof(MONLINKSTRUCT));
                    Ddeml.DdeUnaccessData(hData);
                    OnLink(mon);
                    return(IntPtr.Zero);
                }

                case Ddeml.MF_POSTMSGS:
                {
                    // Get the MONMSGSTRUCT object.
                    int          length = 0;
                    IntPtr       phData = Ddeml.DdeAccessData(hData, ref length);
                    MONMSGSTRUCT mon    = (MONMSGSTRUCT)Marshal.PtrToStructure(phData, typeof(MONMSGSTRUCT));
                    Ddeml.DdeUnaccessData(hData);
                    OnPost(mon);
                    return(IntPtr.Zero);
                }

                case Ddeml.MF_SENDMSGS:
                {
                    // Get the MONMSGSTRUCT object.
                    int          length = 0;
                    IntPtr       phData = Ddeml.DdeAccessData(hData, ref length);
                    MONMSGSTRUCT mon    = (MONMSGSTRUCT)Marshal.PtrToStructure(phData, typeof(MONMSGSTRUCT));
                    Ddeml.DdeUnaccessData(hData);
                    OnSend(mon);
                    return(IntPtr.Zero);
                }
                }
                break;

            case Ddeml.XTYP_ADVDATA:
                unsafe
                {
                    sbyte *pSZ   = stackalloc sbyte[Ddeml.MAX_STRING_SIZE];
                    int    len   = Ddeml.DdeQueryString(_InstanceId, hsz1, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string topic = new string(pSZ);
                    len = Ddeml.DdeQueryString(_InstanceId, hsz2, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string item = new string(pSZ);
                    byte * bt   = stackalloc byte[Ddeml.MAX_STRING_SIZE];
                    len = Ddeml.DdeGetData(hData, bt, Ddeml.MAX_STRING_SIZE, 0);
                    byte[] bytes = new byte[len]; for (int i = 0; i < len; i++)
                    {
                        bytes[i] = *bt++;
                    }
                    ;
                    if (hData != IntPtr.Zero)
                    {
                        Ddeml.DdeUnaccessData(hData);
                    }
                    return(new IntPtr((int)OnAdvData(uFmt, topic, item, bytes)));
                }

            case Ddeml.XTYP_ADVREQ:
                unsafe
                {
                    sbyte *pSZ   = stackalloc sbyte[Ddeml.MAX_STRING_SIZE];
                    int    len   = Ddeml.DdeQueryString(_InstanceId, hsz1, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string topic = new string(pSZ);
                    len = Ddeml.DdeQueryString(_InstanceId, hsz2, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string item = new string(pSZ);
                    byte[] data = OnAdvReq(uFmt, topic, item);
                    // Create and return the data handle representing the data being advised.
                    if (data != null && data.Length > 0)
                    {
                        return(Ddeml.DdeCreateDataHandle(_InstanceId, data, data.Length, 0, hsz2, uFmt, 0));;
                    }
                    // This transaction could not be Ddeml.DDE_FACK here.
                    return(IntPtr.Zero);
                }

            case Ddeml.XTYP_ADVSTART:
                unsafe
                {
                    // Get the item name from the hsz2 string handle.
                    sbyte *pSZ   = stackalloc sbyte[Ddeml.MAX_STRING_SIZE];
                    int    len   = Ddeml.DdeQueryString(_InstanceId, hsz1, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string topic = new string(pSZ);
                    len = Ddeml.DdeQueryString(_InstanceId, hsz2, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string item = new string(pSZ);
                    // Get a value indicating whether an advise loop should be initiated from the subclass.
                    //AdvStart(hConv, item, uFmt, Ddeml.XTYPF_ACKREQ);
                    return(OnAdvStart(uFmt, topic, item) ? new IntPtr(1) : IntPtr.Zero);
                }

            case Ddeml.XTYP_ADVSTOP:
                unsafe
                {
                    // Get the item name from the hsz2 string handle.
                    sbyte *pSZ   = stackalloc sbyte[Ddeml.MAX_STRING_SIZE];
                    int    len   = Ddeml.DdeQueryString(_InstanceId, hsz1, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string topic = new string(pSZ);
                    len = Ddeml.DdeQueryString(_InstanceId, hsz2, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string item = new string(pSZ);
                    // Inform the subclass that the advise loop has been terminated.
                    //AdvStop(hConv, item, uFmt);
                    OnAdvStop(uFmt, topic, item);
                    break;
                }

            case Ddeml.XTYP_CONNECT:
                unsafe
                {
                    sbyte *pSZ   = stackalloc sbyte[Ddeml.MAX_STRING_SIZE];
                    int    len   = Ddeml.DdeQueryString(_InstanceId, hsz1, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string topic = new string(pSZ);
                    // Get a value from the subclass indicating whether the connection should be allowed.
                    return(OnConnect(topic, new CONVCONTEXT(), true) ? new IntPtr(1) : IntPtr.Zero);
                }

            case Ddeml.XTYP_CONNECT_CONFIRM:
                unsafe
                {
                    sbyte *pSZ   = stackalloc sbyte[Ddeml.MAX_STRING_SIZE];
                    int    len   = Ddeml.DdeQueryString(_InstanceId, hsz1, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string topic = new string(pSZ);
                    // Create a Conversation object and add it to the hConv table.
                    _ConversationTable.Add(hConv);
                    // Inform the subclass that a hConv has been established.
                    OnConnectConfirm(topic, true);
                    break;
                }

            case Ddeml.XTYP_DISCONNECT:
            {
                // Remove the Conversation from the hConv table.
                _ConversationTable.Remove(hConv);
                // Inform the subclass that the hConv has been disconnected.
                OnDisconnect(true);
                // Return zero to indicate that there are no problems.
                return(IntPtr.Zero);
            }

            case Ddeml.XTYP_EXECUTE:
                unsafe
                {
                    // Get the command from the data handle.
                    sbyte *pSZ   = stackalloc sbyte[Ddeml.MAX_STRING_SIZE];
                    int    len   = Ddeml.DdeQueryString(_InstanceId, hsz1, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string topic = new string(pSZ);
                    byte * bt    = stackalloc byte[Ddeml.MAX_STRING_SIZE];
                    len = Ddeml.DdeGetData(hData, bt, Ddeml.MAX_STRING_SIZE, 0);
                    string command = new string((sbyte *)bt);
                    // Send the command to the subclass and get the resul
                    return(new IntPtr((int)OnExecute(topic, command.TrimEnd('\0'))));
                }

            case Ddeml.XTYP_POKE:
                unsafe
                {
                    // Get the item name from the hsz2 string handle.
                    sbyte *pSZ   = stackalloc sbyte[Ddeml.MAX_STRING_SIZE];
                    int    len   = Ddeml.DdeQueryString(_InstanceId, hsz1, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string topic = new string(pSZ);
                    len = Ddeml.DdeQueryString(_InstanceId, hsz2, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string item = new string(pSZ);
                    byte * bt   = stackalloc byte[Ddeml.MAX_STRING_SIZE];
                    len = Ddeml.DdeGetData(hData, bt, Ddeml.MAX_STRING_SIZE, 0);
                    byte[] data = new byte[len]; for (int i = 0; i < len; i++)
                    {
                        data[i] = *bt++;
                    }
                    ;
                    // Send the data to the subclass and get the resul
                    return(new IntPtr((int)OnPoke(uFmt, topic, item, data)));
                }

            case Ddeml.XTYP_REQUEST:
                unsafe
                {
                    // Get the item name from the hsz2 string handle.
                    sbyte *pSZ   = stackalloc sbyte[Ddeml.MAX_STRING_SIZE];
                    int    len   = Ddeml.DdeQueryString(_InstanceId, hsz1, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string topic = new string(pSZ);
                    len = Ddeml.DdeQueryString(_InstanceId, hsz2, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string item = new string(pSZ);
                    // Send the request to the subclass and get the resul
                    var result = OnRequest(uFmt, topic, item);
                    // Return a data handle if the subclass Ddeml.DDE_FACK the request successfully.
                    if (result != null)
                    {
                        return(Ddeml.DdeCreateDataHandle(_InstanceId, result, result.Length, 0, hsz2, uFmt, 0));
                    }
                    // Return DDE_FDdeml.DDE_FNOTDdeml.DDE_FACK if the subclass did not process the command.
                    return(new IntPtr(Ddeml.DDE_FNOTPROCESSED));
                }

            case Ddeml.XTYP_XACT_COMPLETE:
                unsafe
                {
                    sbyte *pSZ   = stackalloc sbyte[Ddeml.MAX_STRING_SIZE];
                    int    len   = Ddeml.DdeQueryString(_InstanceId, hsz1, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string topic = new string(pSZ);
                    len = Ddeml.DdeQueryString(_InstanceId, hsz2, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string item = new string(pSZ);
                    OnXactComplete(uFmt, topic, item, hData, dwData1);
                    break;
                }

            case Ddeml.XTYP_WILDCONNECT:
            {
                // This library does not support wild connects.
                return(IntPtr.Zero);
            }

            case Ddeml.XTYP_ERROR:
            {
                // Get the error code, but do nothing with it at this time.
                return(IntPtr.Zero);
            }

            case Ddeml.XTYP_REGISTER:
                unsafe
                {
                    // Get the service name from the hsz1 string handle.
                    sbyte *pSZ = stackalloc sbyte[Ddeml.MAX_STRING_SIZE];
                    int    len = Ddeml.DdeQueryString(_InstanceId, hsz1, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string bas = new string(pSZ);
                    len = Ddeml.DdeQueryString(_InstanceId, hsz2, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string inst = new string(pSZ);
                    OnRegister(bas, inst);
                    return(IntPtr.Zero);
                }

            case Ddeml.XTYP_UNREGISTER:
                unsafe
                {
                    sbyte *pSZ = stackalloc sbyte[Ddeml.MAX_STRING_SIZE];
                    int    len = Ddeml.DdeQueryString(_InstanceId, hsz1, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string bas = new string(pSZ);
                    len = Ddeml.DdeQueryString(_InstanceId, hsz2, pSZ, Ddeml.MAX_STRING_SIZE, Ddeml.CP_WINANSI);
                    string inst = new string(pSZ);
                    OnUnRegister(bas, inst);
                    return(IntPtr.Zero);
                }
            }
            return(IntPtr.Zero);
        }