VB6上的blutooth连接关联码 [英] association code of blutooth connection on VB6

查看:123
本文介绍了VB6上的blutooth连接关联码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,每个人,



我将演变在VB6上写的应用程序。这个应用程序使用蓝牙连接与硬件进行通信。我成功地进行了沟通,但操作系统声称我的代码是将蓝牙与我的电脑相关联。目标是关联必须对用户透明,因为他在一小时内多次使用此应用程序。



任何人都知道这个问题的解决方案。



谢谢

hello every body,

i''m evolve an application writen on VB6. this app use bluetooth connection to communicate with the hardware. i succed to communicate but the OS claim me a code to associate the bluetooth with my pc. The goal is the association must be transparent for the user because he use this app many times in hour.

any one know a solution for this problem.

thanks

推荐答案

有一个解决方案,但它不是完全运行的。通过以下步骤使用InTheHand.Net.Personal.dll创建一个DLL ActiveX:

以管理员身份启动VS2010。

打开一个类库项目(exmaple - MyProject) 。

- 为项目添加一个新界面(参见下面的例子)。

- 添加一个使用System.Runtime.InteropServices;到文件

- 将InterfaceType,Guid属性添加到界面。

- 您可以使用工具生成Guid->生成GUID(选项4)。 />
- 添加一个实现该接口的类。

- 将属性ClassInterface,Guid,ProgId添加到接口。

- ProgId约定是{namespace }。{class}

在AssemblyInfo文件中项目的Properties文件夹下,将ComVisible设置为true。

- 在项目属性菜单中,在构建选项卡标记中注册COM互操作

建立项目



there is a solution but it is not completly operating. Create a dll ActiveX by following these steps with "InTheHand.Net.Personal.dll" :
Start VS2010 as administrator.
Open a class library project (exmaple - MyProject).
- Add a new interface to the project (see example below).
- Add a using System.Runtime.InteropServices; to the file
- Add the attributes InterfaceType, Guid to the interface.
- You can generate a Guid using Tools->Generate GUID (option 4).
- Add a class that implement the interface.
- Add the attributes ClassInterface, Guid, ProgId to the interface.
- ProgId convention is {namespace}.{class}
Under the Properties folder in the project in the AssemblyInfo file set ComVisible to true.
- In the project properties menu, in the build tab mark "Register for COM interop"
Build the project

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Runtime.InteropServices;

namespace Launcher
{

    [InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")]
    public interface ILauncher
    {
        void launch();
    }

    [ClassInterface(ClassInterfaceType.None), Guid("YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYY"), ProgId("Launcher.Launcher")]
    public class Launcher : ILauncher
    {
        private string path = null;

        public void launch()
        {
            Console.WriteLine("I launch scripts for a living.");

        }

    }
}





- 和VB使用COM:

set obj = createObject(PSLauncher.PSLauncher)obj.launch()









下载本网站的InTheHand.Net.Personal.dll:

网站





感谢来自网站的Eyal stackoverflow


我的dll代码可以连接:



there is my dll code to connect:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InTheHand.Net.Sockets;
using InTheHand.Net.Bluetooth;
using System.Windows.Forms;
using InTheHand.Net;
using System.Runtime.InteropServices;

namespace LibrairieDeConnexionBluetoothAvecDLL
{

    [InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("220081A3-4B8F-4834-A47D-0531877D483E"), ComVisible(true)]
    public interface IBluetooth
    {
        bool connection();
        void initialisation();
        void detecterLesDispositifs();
        void choisirUnDispositif();
        void ajouterLesControleALaFentreDeConnexion(Form fenetreDeSelectionDuBluetooth, ListBox listeDesAdresseDesPériphérique, ListBox listeDesNomDesPériphérique, Button Connexion, Button refresh);
        void confgurerFenetreDeConnexion(Form fenetreDeSelectionDuBluetooth);
        void configurerLeBouton(Button Connexion, int marginGauche, int marginHaut, string nom, bool etat);
        void configurerLaListe(ListBox liste, int with, int height, int marginGauche, int marginHaut, bool enable);
        void seConnecter();
        void Win32AuthCallbackHandler(object sender, InTheHand.Net.Bluetooth.BluetoothWin32AuthenticationEventArgs e);
        void listeDesNomDesPériphérique_SelectedIndexChanged(object sender, EventArgs e);
        void Refresh_Click(object sender, EventArgs e);
        void Connexion_Click(object sender, EventArgs e);
    }

    [ClassInterface(ClassInterfaceType.None), Guid("90A2335C-0310-49C1-AF57-E9BF993647D5"), ProgId("LibrairieDeConnexionBluetoothAvecDLL.Bluetooth"), ComVisible(true)]
    public class Bluetooth : UserControl, IBluetooth
    {
        private BluetoothClient listeDePeripheriqueBluetooth;
        private BluetoothClient SerialPort;
        private BluetoothDeviceInfo optifive;
        private Guid service;
        private BluetoothDeviceInfo[] bdi;
        private BluetoothRadio radio;
        private Form fenetreDeSelectionDuBluetooth;
        private ListBox listeDesNomDesPériphériques;
        private ListBox listeDesAdresseDesPériphériques;
        private Button Connexion;
        private Button Refresh;

        public bool connection()
        {
            initialisation();
            detecterLesDispositifs();
            listeDesNomDesPériphériques.SelectedIndexChanged += new System.EventHandler(
                listeDesNomDesPériphérique_SelectedIndexChanged);
            Refresh.Click += new System.EventHandler(Refresh_Click);
            Connexion.Click += new System.EventHandler(Connexion_Click);

            return optifive.Connected;
        }

        public void initialisation()
        {
            radio = BluetoothRadio.PrimaryRadio;
            if (radio != null && radio.Mode == RadioMode.PowerOff)
            {
                BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
            }
            listeDePeripheriqueBluetooth = new BluetoothClient();
            service = BluetoothService.SerialPort;

            fenetreDeSelectionDuBluetooth = new Form();
            confgurerFenetreDeConnexion(fenetreDeSelectionDuBluetooth);
            listeDesNomDesPériphériques = new ListBox();
            listeDesAdresseDesPériphériques = new ListBox();
            Connexion = new Button();
            Refresh = new Button();
            configurerLaListe(listeDesNomDesPériphériques, 200, 300, 5, 5, true);
            configurerLaListe(listeDesAdresseDesPériphériques, 200, 300, 220, 5, false);
            configurerLeBouton(Connexion, 220, 310, "Connexion", false);
            configurerLeBouton(Refresh, 5, 310, "Refresh", true);
            ajouterLesControleALaFentreDeConnexion(fenetreDeSelectionDuBluetooth, listeDesAdresseDesPériphériques, listeDesNomDesPériphériques, Connexion, Refresh);
            fenetreDeSelectionDuBluetooth.Show();
        }

        public void detecterLesDispositifs()
        {
            //this will take a while...
            Cursor.Current = Cursors.WaitCursor;
            bdi = listeDePeripheriqueBluetooth.DiscoverDevices();
            //bind the combo
            if (listeDesAdresseDesPériphériques.Items.Count>0)
                listeDesAdresseDesPériphériques.Items.Clear();
            if(listeDesNomDesPériphériques.Items.Count>0)
                listeDesNomDesPériphériques.Items.Clear();
            bdi.ToList().ForEach(delegate(BluetoothDeviceInfo Device)
            {
                listeDesNomDesPériphériques.Items.Add(Device.DeviceName);
                listeDesAdresseDesPériphériques.Items.Add(Device.DeviceAddress.ToString().Insert(10, ":").Insert(8, ":").Insert(6, ":").Insert(4, ":").Insert(2, ":"));
            });
            Cursor.Current = Cursors.Default;

        }


        public void choisirUnDispositif()
        {
            bdi.ToList().ForEach(delegate(BluetoothDeviceInfo device)
            {
                if (device.DeviceName == listeDesNomDesPériphériques.SelectedItem.ToString().Replace(":", ""))
                    optifive = device;
            });
        }

        public void ajouterLesControleALaFentreDeConnexion(Form fenetreDeSelectionDuBluetooth, ListBox listeDesAdresseDesPériphérique, ListBox listeDesNomDesPériphérique, Button Connexion, Button refresh)
        {
            fenetreDeSelectionDuBluetooth.Controls.Add(listeDesNomDesPériphérique);
            fenetreDeSelectionDuBluetooth.Controls.Add(listeDesAdresseDesPériphérique);
            fenetreDeSelectionDuBluetooth.Controls.Add(Connexion);
            fenetreDeSelectionDuBluetooth.Controls.Add(refresh);
        }

        public void confgurerFenetreDeConnexion(Form fenetreDeSelectionDuBluetooth)
        {
            fenetreDeSelectionDuBluetooth.StartPosition = FormStartPosition.CenterScreen;
            fenetreDeSelectionDuBluetooth.Height = 378;
            fenetreDeSelectionDuBluetooth.Width = 445;
            fenetreDeSelectionDuBluetooth.Text = "Connexion Bluetooth";
        }

        public void configurerLeBouton(Button Connexion, int marginGauche, int marginHaut, string nom, bool etat)
        {
            Connexion.Left = marginGauche;
            Connexion.Top = marginHaut;
            Connexion.Width = 100;//height==23
            Connexion.Text = nom;
            Connexion.Enabled = etat;
        }

        public void configurerLaListe(ListBox liste, int with, int height, int marginGauche, int marginHaut, bool enable)
        {
            liste.Height = height;
            liste.Width = with;
            liste.Left = marginGauche;
            liste.Top = marginHaut;
            liste.Enabled = enable;
            if (liste == null)
                MessageBox.Show("n'éxiste pas");
            else
                MessageBox.Show("éxiste");
        }


        public void seConnecter()
        {
            try
            {
                BluetoothWin32Authentication authetification = new BluetoothWin32Authentication(Win32AuthCallbackHandler);
                SerialPort = new BluetoothClient();
                SerialPort.Connect(new BluetoothEndPoint(optifive.DeviceAddress, service));
            }
            catch (Exception ex)
            {
                MessageBox.Show("n'arrive pas a se connecter : " + ex.Message);
            }
                    
        }





        public void Win32AuthCallbackHandler(object sender, InTheHand.Net.Bluetooth.BluetoothWin32AuthenticationEventArgs e)
        {
            // Note we assume here that 'Legacy' pairing is being used,
            // and thus we only set the Pin property!
            string address = e.Device.DeviceAddress.ToString();
            Console.WriteLine("Received an authentication request from address " + address);
            //
            // compare the first 8 hex numbers, this is just a special case because in the
            // used scenario the model of the devices can be identified by the first 8 hex
            // numbers, the last 4 numbers being the device specific part.

            // send authentication response
            e.Pin = "0000";

            e.Confirm = true;
        }


        public void listeDesNomDesPériphérique_SelectedIndexChanged(object sender, EventArgs e)
        {
            choisirUnDispositif();
            listeDesAdresseDesPériphériques.SelectedIndex = listeDesNomDesPériphériques.SelectedIndex;
            Connexion.Enabled = true;
        }


        public void Refresh_Click(object sender, EventArgs e)
        {
            detecterLesDispositifs();
        }


        public void Connexion_Click(object sender, EventArgs e)
        {
            seConnecter();
        }


    }
}


这篇关于VB6上的blutooth连接关联码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆