Esempio n. 1
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //Test message//
            /*
            
            {
                Data = Encoding.UTF8.GetBytes(message),
                DataLength = message.Length
            };*/
            MessengerInterop.Init();
            mrh = MessageRecievedHandler;
            MessengerInterop.RegisterObserver(mrh, null);
            var t = await MessengerC.Login();

            string message = "Hello World";
            var data = Encoding.UTF8.GetBytes(message + '\0');


            IntPtr dataPointer = IntPtr.Zero;
            try
            {
                var size = Marshal.SizeOf(data[0])*data.Length;
                dataPointer = Marshal.AllocHGlobal(size);
                Marshal.Copy(data, 0, dataPointer, data.Length);
                var bytes = new BinaryData()
                {
                    Data = dataPointer,
                    DataLength = data.Length
                };

                MessageBox.Show(t.ToString());
                MessengerInterop.SendMessageWrapper("eldar1@dordzhiev", ref bytes);
                await Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                {
                    Messages.Add(message);
                }));
                
                var temp = (await MessengerC.RequestActiveUsers()).UserList;
                UsersList = new ObservableCollection<User>(temp);
            }
            finally
            {
                if (dataPointer != IntPtr.Zero) Marshal.FreeHGlobal(dataPointer);
            }


            //Init and Login

        }
Esempio n. 2
0
 public static extern void SendMessageWrapper([MarshalAs(UnmanagedType.LPStr)] string recepient, ref BinaryData message);
Esempio n. 3
0
        private async void sendButton_Click(object sender, RoutedEventArgs e)
        {
            string message = writeTextBox.Text;
            var data = Encoding.UTF8.GetBytes(message + '\0');


            IntPtr dataPointer = IntPtr.Zero;
            try
            {
                var size = Marshal.SizeOf(data[0])*data.Length;
                dataPointer = Marshal.AllocHGlobal(size);
                Marshal.Copy(data, 0, dataPointer, data.Length);
                var bytes = new BinaryData()
                {
                    Data = dataPointer,
                    DataLength = data.Length
                };

                MessengerInterop.SendMessageWrapper(recepientTextBox.Text, ref bytes);
                await Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                {
                    Messages.Add(message);
                }));
            }
            finally
            {
                if (dataPointer != IntPtr.Zero) Marshal.FreeHGlobal(dataPointer);
            }
        }