Bonjour,
Je travail sur un projet de domotique utilisant un appareil Telldus. Il fournissent une DLL pour pouvoir gérer l'appareil.
Dans cette DLL se trouve une API pour déclencher un Event lors du changement d'état d'un Device (exemple contact de porte).
Voici ce que j'ai dans la doc (c'est très succinct) :
int WINAPI tdRegisterDeviceEvent (TDDeviceEvent eventFunction, void *context)

Register a callback that will receive device events.

Parameters:
eventFunction Callback function.
context Pointer that will be passed back in the callback.

Returns:
An id identifying the callback. Pass this id to tdUnregisterCallback() to stop receiving callbacks.
et voici la documentation pour le type TDDeviceEvent :
typedef void(* TDDeviceEvent )(int deviceId, int method, const char *data, int callbackId, void *context)

The callback type for device events.

Attention:
The callback will be called by another thread than the thread used by the application and some measures must be taken to synchronize it with the main thread.

Parameters:
deviceId The id of the device that changed.
method The new device state. Can be TELLSTICK_TURNON, TELLSTICK_TURNOFF, etc.
data If method is TELLSTICK_DIM this holds the current value as a human readable string, example "128" for 50%.
callbackId The id of the callback.
context The pointer passed when registering for the event.
Comme vous pouvez le remarquer tout est en C, en effet c'est le language qu'ils utilisent.

Voici donc ce que j'ai fait:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Public Class Form1
    Dim RegcallbackId As Long
    Dim Dcontext As Object = Nothing
 
    Public Delegate Sub TDDeviceEvent(ByVal DeviceId As Long, ByVal method As Long, ByRef data As String, ByVal callbackId As Long, ByRef context As Object)
 
    Public Declare Function tdRegisterDeviceEvent Lib "TelldusCore.dll" (ByRef TDDeviceEvent As TDDeviceEvent, ByRef context As Object) As Long
 
    Public Sub DeviceEvent(ByVal DeviceId As Long, ByVal method As Long, ByRef data As String, ByVal callbackId As Long, ByRef context As Object)
        MsgBox("tada")
    End Sub
 
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim DEvent As TDDeviceEvent
        DEvent = New TDDeviceEvent(AddressOf DeviceEvent)
 
        RegcallbackId = tdRegisterDeviceEvent(DEvent, Dcontext)
 
    End Sub
 
End Class
mais dès que j'ouvre mon contact de porte ... "vshost32.exe à cessé de fonctionné ..." (j'ai testé d'autres API de cette même DLL, celles permettant d'envoyer des ordres à certains Device tel qu'allumer une lumière ... et tout fonctionne sans problème)

Je pense que c'est en rapport avec ce qu'il est écrit dans la doc de TDDeviceEvent :
The callback will be called by another thread than the thread used by the application and some measures must be taken to synchronize it with the main thread.
Mais je ne sais pas de quelles mesures ils parlent

Toute aide sera la bienvenue.
D'avance merci