Ejemplo n.º 1
0
        public unsafe bool Connect()
        {
            IntPtr hConv, hszService, hszTopic;

            if (dwDDEInst != 0)
            {
                Ddeml.DdeUninitialize(dwDDEInst);
                dwDDEInst = 0;
            }
            if (hconvCurrent != IntPtr.Zero)
            {
                Ddeml.DdeDisconnect(hconvCurrent);
                hconvCurrent = IntPtr.Zero;
            }
            ;
            //如果是第一次,则什么也不做
            Ddeml.DdeInitialize(ref dwDDEInst, _Callback, 0x3f000, 0);
            // Connect to the server
            hszTopic   = Ddeml.DdeCreateStringHandle(dwDDEInst, _topic, Ddeml.CP_WINANSI);
            hszService = Ddeml.DdeCreateStringHandle(dwDDEInst, _server, Ddeml.CP_WINANSI);
            CONVCONTEXT cc = new CONVCONTEXT();

            cc.cb = sizeof(CONVCONTEXT);
            hConv = Ddeml.DdeConnect(dwDDEInst, hszService, hszTopic, ref cc);
            //int DdeErrcode = Win32.DdeGetLastError(dwDDEInst);

            Ddeml.DdeFreeStringHandle(dwDDEInst, hszTopic);
            Ddeml.DdeFreeStringHandle(dwDDEInst, hszService);

            if (hConv != IntPtr.Zero)
            {
                if (hconvCurrent != IntPtr.Zero)
                {
                    Ddeml.DdeDisconnect(hconvCurrent);
                }
                hconvCurrent = hConv;
                _connected   = true;
                return(true);
            }
            else
            {
                _connected = false;
                return(false);
            }
        }
Ejemplo n.º 2
0
 public void Uninitialize()
 {
     Ddeml.DdeUninitialize(_InstanceId);
 }