Author Topic: События и C#  (Read 2467 times)

Offline Roman

  • Newbie
  • *
  • Posts: 11
  • Karma: 0
События и C#
« on: December 13, 2006, 05:15:37 PM »
Здравствуйте.

Не получается получать события от объекта BFBluetoothDiscoveryX в C#.
1.    В данном случае bt_OnStartSearch() не вызывается:
Code: [Select]
class Program
{
private BFBluetoothDiscoveryX bt;

public Program()
{
bt = new BFBluetoothDiscoveryX();
bt.OnStartSearch += new IBFBluetoothDiscoveryXEvents_OnStartSearchEventHandler(bt_OnStartSearch);
bt.Monitoring = true;
}

void bt_OnStartSearch()
{
Console.WriteLine("OnStartSearch()");
}

static void Main(string[] args)
{
Program prg = new Program();
Console.WriteLine("*** Press Enter to quit ***");
Console.Read();
}

2. В данном случае ни одно из событий не вызывается:
Code: [Select]
public class BluetoothConnection : IBFBluetoothDiscoveryXEvents
{
private IConnectionPoint icp = null;
private int cookie = -1;

public BluetoothConnection()
{
disco = new BFBluetoothDiscoveryX();

IConnectionPointContainer icpc = (IConnectionPointContainer)disco;
Guid g = typeof(IBFBluetoothDiscoveryXEvents).GUID;
icpc.FindConnectionPoint(ref g, out icp);
icp.Advise(this, out cookie);

disco.Monitoring = true;
}

public void OnDeviceFound(BFBluetoothDeviceX Device) { Console.WriteLine("OnDeviceFound()"); }

public void OnDeviceLost(BluetoothFrameworkX.BFBluetoothDeviceX Device) { Console.WriteLine("OnDeviceLost()"); }

public void OnStartMonitoring() { Console.WriteLine("OnStartMonitoring()"); }

public void OnStartSearch() { Console.WriteLine("OnStartSearch()"); }

public void OnStopMonitoring() { Console.WriteLine("OnStopMonitoring()"); }

public void OnStopSearch() { System.Diagnostics.Debugger.Break(); }

static void Main(string[] args)
{
BluetoothConnection prg = new BluetoothConnection ();
Console.WriteLine("*** Press Enter to quit ***");
Console.Read();
}
}

3. При попытке привязаться к более чем одному событию (всё равно какое будет первым) возникает "Exception from HRESULT: 0x80040202"
Code: [Select]
class Program
{
private BFBluetoothDiscoveryX bt;

public Program()
{
bt = new BFBluetoothDiscoveryX();
bt.OnDeviceFound += new IBFBluetoothDiscoveryXEvents_OnDeviceFoundEventHandler(bt_OnDeviceFound);
bt.OnDeviceLost += new IBFBluetoothDiscoveryXEvents_OnDeviceLostEventHandler(bt_OnDeviceLost); // EXCEPTION RAISED
bt.OnStartMonitoring += new IBFBluetoothDiscoveryXEvents_OnStartMonitoringEventHandler(bt_OnStartMonitoring);
bt.OnStartSearch += new IBFBluetoothDiscoveryXEvents_OnStartSearchEventHandler(bt_OnStartSearch);
bt.OnStopMonitoring += new IBFBluetoothDiscoveryXEvents_OnStopMonitoringEventHandler(bt_OnStopMonitoring);
bt.OnStopSearch += new IBFBluetoothDiscoveryXEvents_OnStopSearchEventHandler(bt_OnStopSearch);
bt.Monitoring = true;
}

void bt_OnStartSearch() { Console.WriteLine("OnStartSearch()"); }
void bt_OnDeviceLost(BFBluetoothDeviceX Device) { Console.WriteLine("OnDeviceLost()"); }
void bt_OnDeviceFound(BFBluetoothDeviceX Device) { Console.WriteLine("OnDeviceFound()"); }
void bt_OnStopSearch() { Console.WriteLine("OnStopSearch()"); }
void bt_OnStopMonitoring() { Console.WriteLine("OnStopMonitoring()"); }
void bt_OnStartMonitoring() { Console.WriteLine("OnStartMonitoring()"); }

static void Main(string[] args)
{
Program prg = new Program();
Console.WriteLine("*** Press Enter to quit ***");
Console.Read();
}

Ранее (с другими COM-объектами) с такими проблемами не сталкивался.
Можете мне почомь?

Заранее спасибо.
Роман.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2491
  • Karma: 1000
    • Wireless Communication Library
Re: ??????? ? C#
« Reply #1 on: December 14, 2006, 09:07:25 AM »
??? ????? ? ??????? ???????
http://www.btframework.com/files/demo/bfx_net_demo.zip

????? ??? BDS 2006 C#. ?? ??????? ????? ???? ? MSVC 2005 ???. ?????? ?????? ???????. ?????? ??????? ? MSVC 2005 ?????? ? ???????? ???? C# ?????.
WCL - Wireless Communication Library
TextBlue - Bluetooth Proximity Marketing Software
WCL Phone Explorer - Free Phone Content Manager

Offline Roman

  • Newbie
  • *
  • Posts: 11
  • Karma: 0
Re: События и C#
« Reply #2 on: December 14, 2006, 02:35:58 PM »
Mike Petrichenko, большое спасибо за пример.

Он отлично работает c .NET Framework 1.1, но отказывается с .NET 2.0:
При запуске любого WindowsForms-приложения с контролом BluetoothDiscoveryX на форме появляется splash-окно демо версии Вашей библиотеки, пустое - один фон без надписей и кнопки, и виснет. При добавлении контрола на форму splash-окно появляется нормально.
Само собой библиотека будет приобритена, но только после того будет проверен основной её функционал внутри нашей системы.
Есть возможность исправить этот баг?

И еще один вопрос - возможно ли использовать библиотеку как простой COM-объект, без ОСХ-контрола? Т.к. приложение её использующее - не WindowsForms-приложение.

Заранее спасибо.
Роман.



Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2491
  • Karma: 1000
    • Wireless Communication Library
Re: ??????? ? C#
« Reply #3 on: December 14, 2006, 02:50:51 PM »
??????? ??????? ?????!

??????? ?? ???-??????. ? ??????? ? NET 2.0.

???????????? ???????? ???????????? ? ??? COM ?????????. ??????? ??? ??????? ??? OCX ??? COM. ?? ????? ???? ????? ????? ???? ? ?????? ??????? ??????? DLL (??? ?????? COM ? OCX)?
WCL - Wireless Communication Library
TextBlue - Bluetooth Proximity Marketing Software
WCL Phone Explorer - Free Phone Content Manager

Offline Roman

  • Newbie
  • *
  • Posts: 11
  • Karma: 0
Re: События и C#
« Reply #4 on: December 14, 2006, 04:14:04 PM »
Теоретически возможно использовать и как COM компонент. Разницы нет никакой что OCX что COM.
Так я и попытался вначале использовать его как COM - результаты описаны в первом посте.

Но может быть будет проще если я сделаю обычную сишнуюю DLL (без всяких COM и OCX)?
Если это не затруднительно - то можно и так.

Большое спасибо за оперативную поддержку.
Роман.

Offline Roman

  • Newbie
  • *
  • Posts: 11
  • Karma: 0
Re: События и C#
« Reply #5 on: December 14, 2006, 04:57:00 PM »
Еще важны события... хотя-бы какое-нибудь одно.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2491
  • Karma: 1000
    • Wireless Communication Library
Re: ??????? ? C#
« Reply #6 on: December 14, 2006, 05:38:32 PM »
OK. I will.
WCL - Wireless Communication Library
TextBlue - Bluetooth Proximity Marketing Software
WCL Phone Explorer - Free Phone Content Manager

Offline Roman

  • Newbie
  • *
  • Posts: 11
  • Karma: 0
Re: События и C#
« Reply #7 on: December 21, 2006, 09:57:46 AM »
Здравствуйте, Mike.

Решен баг с использованием библиотеки в форме OCX-контрола под .NET 2.0 - оказалось что зависание splash-окна происходит лишь при запуске проекта из студии (и в debug, и в release конфигурации). При запуске .exe извне студии - всё ок.
В связи с этим необходимость в обычной DLL отпала.

Есть еще один вопрос по передаче файлов, но я его задам, пожалуй, в отдельной теме.

Роман.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2491
  • Karma: 1000
    • Wireless Communication Library
Re: ??????? ? C#
« Reply #8 on: December 21, 2006, 10:48:57 AM »
OK :)
?? ??? ????? ????????? ? ??? ?????
WCL - Wireless Communication Library
TextBlue - Bluetooth Proximity Marketing Software
WCL Phone Explorer - Free Phone Content Manager

Offline Rob

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: События и C#
« Reply #9 on: August 29, 2007, 08:12:10 PM »
Hi Mike,

This was the only thread where I found something related to my error.

I am getting this error: Exception from HRESULT: 0x80040202
when i try to declare any of these three event handlers:

btDiscovering.OnDeviceLost += new IBFBluetoothDiscoveryXEvents_OnDeviceLostEventHandler(BluetoothDiscovery_OnDeviceLost);
btDiscovering.OnStartMonitoring += new IBFBluetoothDiscoveryXEvents_OnStartMonitoringEventHandler(BluetoothDiscovery_OnStartMonitoring);
btDiscovering.OnStopMonitoring += new IBFBluetoothDiscoveryXEvents_OnStopMonitoringEventHandler(BluetoothDiscovery_OnStopMonitoring);

My application compiles successfully, 0 errors, 0 warning, but crashes when you try to run it.

I am using Visual Studio 2005 Pro, .Net 2.0, C#, and Demo Framework dll v5.22.0.0

Is there anything you can think of that would cause or fix this error?

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2491
  • Karma: 1000
    • Wireless Communication Library
Re: ??????? ? C#
« Reply #10 on: August 29, 2007, 08:53:07 PM »
Good day!

Here is the solution. Somewhere on forum i have posted it already (and other sample too).
WCL - Wireless Communication Library
TextBlue - Bluetooth Proximity Marketing Software
WCL Phone Explorer - Free Phone Content Manager