Пример #1
0
            protected override void WndProc(ref Message msg)
            {
                //Note: all parameters must be manually marshalled!

                #region BTMSG_DEVICEFOUND
                //--------------------------------
                // BTMSG_DEVICEFOUND
                //--------------------------------
                if (msg.Msg == BTMSG_DEVICEFOUND)
                {
                    //WPARAM = 0
                    //LPARAM = DevFound struct: devclass, devtype, isconnected, devaddr, devname
                    IntPtr p = msg.LParam;

                    //Fill in C# device object with found-device fields
                    BtDevice device = new BtDevice();

                    device.DeviceClass = (Bluetooth.eBTDEVCLASS)Marshal.ReadInt32(p);
                    p = (IntPtr) ((int)p + 4);

                    device.DeviceType = (Bluetooth.eBTDEVTYPE)Marshal.ReadInt32(p);
                    p = (IntPtr) ((int)p + 4);

                    device.IsConnected = Marshal.ReadInt32(p)== 0 ? false : true;
                    p = (IntPtr) ((int)p + 4);

                    device.DeviceAddr = Marshal.PtrToStringUni(p);
                    p = (IntPtr) ((int)p + 48);  //24 TCHARs

                    device.DeviceName = Marshal.PtrToStringUni(p);

                    //Fire BtDevFound event to any listeners
                    if (BtStack.BtDevFound != null)
                        BtStack.BtDevFound(device);

                    //Have to get DLL to do its own memory delete
                    BT_DeletePointer(msg.LParam);
                }
                #endregion

                #region BTMSG_CONNECTION_STATUS
                //--------------------------------
                // BTMSG_CONNECTION_STATUS
                //--------------------------------
                else
                if (msg.Msg == BTMSG_CONNECTION_STATUS)
                {
                    //WPARAM = 0
                    //LPARAM = ConnStatus struct: svctype, status, comport, devaddr, devname
                    IntPtr p = msg.LParam;

                    //Fill in C# ConnStatus object with status info
                    ConnStatus connStatus = new ConnStatus();

                    connStatus.SvcType = (Bluetooth.eBTSVC)Marshal.ReadInt32(p);
                    p = (IntPtr) ((int)p + 4);

                    connStatus.Status = (Bluetooth.eBTCONN_STATUS)Marshal.ReadInt32(p);
                    p = (IntPtr) ((int)p + 4);

                    connStatus.COMPort = Marshal.PtrToStringUni(p);
                    p = (IntPtr) ((int)p + 16);  //8 TCHARs

                    connStatus.DeviceAddr = Marshal.PtrToStringUni(p);
                    p = (IntPtr) ((int)p + 48);  //24 TCHARs

                    connStatus.DeviceName = Marshal.PtrToStringUni(p);

                    //Fire BtConnStatus event to any listeners
                    if (BtStack.BtConnStatus != null)
                        BtStack.BtConnStatus(connStatus);

                    //Have to get DLL to do its own memory delete
                    BT_DeletePointer(msg.LParam);
                }
                #endregion

                #region BTMSG_SENDFILE_PROGRESS
                //--------------------------------
                // BTMSG_SENDFILE_PROGRESS
                //--------------------------------
                else
                if (msg.Msg == BTMSG_SENDFILE_PROGRESS)
                {
                    //WPARAM = completion code
                    //LPARAM = 0

                    //Fire BtSendFileProgress event to any listeners
                    if (BtStack.BtSendFileProgress != null)
                        BtStack.BtSendFileProgress( (Int32) msg.WParam, (Int32) msg.LParam);
                }
                #endregion

                #region BTMSG_SENDFILE_COMPLETE
                //--------------------------------
                // BTMSG_SENDFILE_COMPLETE
                //--------------------------------
                else
                if (msg.Msg == BTMSG_SENDFILE_COMPLETE)
                {
                    //WPARAM = completion code
                    //LPARAM = 0

                    //Fire BtSendFileComplete event to any listeners
                    if (BtStack.BtSendFileComplete != null)
                        BtStack.BtSendFileComplete( (eBTRC) ( (int) msg.WParam));
                }
                #endregion

                #region BTMSG_BC_COMPLETE
                //--------------------------------
                // BTMSG_BC_COMPLETE
                //--------------------------------
                else
                if (msg.Msg == BTMSG_BC_COMPLETE)
                {
                    //WPARAM = completion code
                    //LPARAM = 0

                    //Fire BtBcComplete event to any listeners
                    if (BtStack.BtBcComplete != null)
                        BtStack.BtBcComplete( (eBTRC) ( (int) msg.WParam));
                }
                #endregion

                #region BTMSG_SEARCH_COMPLETE
                //--------------------------------
                // BTMSG_SEARCH_COMPLETE
                //--------------------------------
                else
                if (msg.Msg == BTMSG_SEARCH_COMPLETE)
                {
                    //Fire BtSearchComplete event to any listeners
                    if (BtStack.BtSearchComplete != null)
                        BtStack.BtSearchComplete();
                }
                #endregion

                #region BTMSG_RECVFILE_COMPLETE
                //--------------------------------
                // BTMSG_RECVFILE_COMPLETE
                //--------------------------------
                else
                if (msg.Msg == BTMSG_RECVFILE_COMPLETE)
                {
                    //WPARAM = 0
                    //LPARAM = RecvFile struct: devaddr, devname, filename
                    IntPtr p = msg.LParam;

                    //Fill in C# device object with found-device fields
                    RecvFileInfo info = new RecvFileInfo();

                    info.DeviceAddr = Marshal.PtrToStringUni(p);
                    p = (IntPtr) ((int)p + 48);  //24 TCHARs

                    info.DeviceName = Marshal.PtrToStringUni(p);
                    p = (IntPtr) ((int)p + 512);  //256 TCHARs

                    info.FileName = Marshal.PtrToStringUni(p);

                    //Fire BtRecvFileComplete event to any listeners
                    if (BtStack.BtRecvFileComplete != null)
                        BtStack.BtRecvFileComplete(info);

                    //Have to get DLL to do its own memory delete
                    BT_DeletePointer(msg.LParam);
                }
                #endregion

                base.WndProc(ref msg);
            }
Пример #2
0
            protected override void WndProc(ref Message msg)
            {
                //Note: all parameters must be manually marshalled!

                #region BTMSG_DEVICEFOUND
                //--------------------------------
                // BTMSG_DEVICEFOUND
                //--------------------------------
                if (msg.Msg == BTMSG_DEVICEFOUND)
                {
                    //WPARAM = 0
                    //LPARAM = DevFound struct: devclass, devtype, isconnected, devaddr, devname
                    IntPtr p = msg.LParam;

                    //Fill in C# device object with found-device fields
                    BtDevice device = new BtDevice();

                    device.DeviceClass = (Bluetooth.eBTDEVCLASS)Marshal.ReadInt32(p);
                    p = (IntPtr)((int)p + 4);

                    device.DeviceType = (Bluetooth.eBTDEVTYPE)Marshal.ReadInt32(p);
                    p = (IntPtr)((int)p + 4);

                    device.IsConnected = Marshal.ReadInt32(p) == 0 ? false : true;
                    p = (IntPtr)((int)p + 4);

                    device.DeviceAddr = Marshal.PtrToStringUni(p);
                    p = (IntPtr)((int)p + 48);                       //24 TCHARs

                    device.DeviceName = Marshal.PtrToStringUni(p);

                    //Fire BtDevFound event to any listeners
                    if (BtStack.BtDevFound != null)
                    {
                        BtStack.BtDevFound(device);
                    }

                    //Have to get DLL to do its own memory delete
                    BT_DeletePointer(msg.LParam);
                }
                #endregion

                #region BTMSG_CONNECTION_STATUS
                //--------------------------------
                // BTMSG_CONNECTION_STATUS
                //--------------------------------
                else
                if (msg.Msg == BTMSG_CONNECTION_STATUS)
                {
                    //WPARAM = 0
                    //LPARAM = ConnStatus struct: svctype, status, comport, devaddr, devname
                    IntPtr p = msg.LParam;

                    //Fill in C# ConnStatus object with status info
                    ConnStatus connStatus = new ConnStatus();

                    connStatus.SvcType = (Bluetooth.eBTSVC)Marshal.ReadInt32(p);
                    p = (IntPtr)((int)p + 4);

                    connStatus.Status = (Bluetooth.eBTCONN_STATUS)Marshal.ReadInt32(p);
                    p = (IntPtr)((int)p + 4);

                    connStatus.COMPort = Marshal.PtrToStringUni(p);
                    p = (IntPtr)((int)p + 16);                       //8 TCHARs

                    connStatus.DeviceAddr = Marshal.PtrToStringUni(p);
                    p = (IntPtr)((int)p + 48);                       //24 TCHARs

                    connStatus.DeviceName = Marshal.PtrToStringUni(p);

                    //Fire BtConnStatus event to any listeners
                    if (BtStack.BtConnStatus != null)
                    {
                        BtStack.BtConnStatus(connStatus);
                    }

                    //Have to get DLL to do its own memory delete
                    BT_DeletePointer(msg.LParam);
                }
                #endregion

                #region BTMSG_SENDFILE_PROGRESS
                //--------------------------------
                // BTMSG_SENDFILE_PROGRESS
                //--------------------------------
                else
                if (msg.Msg == BTMSG_SENDFILE_PROGRESS)
                {
                    //WPARAM = completion code
                    //LPARAM = 0

                    //Fire BtSendFileProgress event to any listeners
                    if (BtStack.BtSendFileProgress != null)
                    {
                        BtStack.BtSendFileProgress((Int32)msg.WParam, (Int32)msg.LParam);
                    }
                }
                #endregion

                #region BTMSG_SENDFILE_COMPLETE
                //--------------------------------
                // BTMSG_SENDFILE_COMPLETE
                //--------------------------------
                else
                if (msg.Msg == BTMSG_SENDFILE_COMPLETE)
                {
                    //WPARAM = completion code
                    //LPARAM = 0

                    //Fire BtSendFileComplete event to any listeners
                    if (BtStack.BtSendFileComplete != null)
                    {
                        BtStack.BtSendFileComplete((eBTRC)((int)msg.WParam));
                    }
                }
                #endregion

                #region BTMSG_BC_COMPLETE
                //--------------------------------
                // BTMSG_BC_COMPLETE
                //--------------------------------
                else
                if (msg.Msg == BTMSG_BC_COMPLETE)
                {
                    //WPARAM = completion code
                    //LPARAM = 0

                    //Fire BtBcComplete event to any listeners
                    if (BtStack.BtBcComplete != null)
                    {
                        BtStack.BtBcComplete((eBTRC)((int)msg.WParam));
                    }
                }
                #endregion

                #region BTMSG_SEARCH_COMPLETE
                //--------------------------------
                // BTMSG_SEARCH_COMPLETE
                //--------------------------------
                else
                if (msg.Msg == BTMSG_SEARCH_COMPLETE)
                {
                    //Fire BtSearchComplete event to any listeners
                    if (BtStack.BtSearchComplete != null)
                    {
                        BtStack.BtSearchComplete();
                    }
                }
                #endregion

                #region BTMSG_RECVFILE_COMPLETE
                //--------------------------------
                // BTMSG_RECVFILE_COMPLETE
                //--------------------------------
                else
                if (msg.Msg == BTMSG_RECVFILE_COMPLETE)
                {
                    //WPARAM = 0
                    //LPARAM = RecvFile struct: devaddr, devname, filename
                    IntPtr p = msg.LParam;

                    //Fill in C# device object with found-device fields
                    RecvFileInfo info = new RecvFileInfo();

                    info.DeviceAddr = Marshal.PtrToStringUni(p);
                    p = (IntPtr)((int)p + 48);                       //24 TCHARs

                    info.DeviceName = Marshal.PtrToStringUni(p);
                    p = (IntPtr)((int)p + 512);                       //256 TCHARs

                    info.FileName = Marshal.PtrToStringUni(p);

                    //Fire BtRecvFileComplete event to any listeners
                    if (BtStack.BtRecvFileComplete != null)
                    {
                        BtStack.BtRecvFileComplete(info);
                    }

                    //Have to get DLL to do its own memory delete
                    BT_DeletePointer(msg.LParam);
                }
                #endregion

                base.WndProc(ref msg);
            }