I am trying to detect whenever Android device remove or insert. For RegisterDeviceNotification, this code work fine in VB.NET
Public Class DEV_BROADCAST_DEVICEINTERFACE
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
Public dbcc_classguid As Guid
Public dbcc_name As Short
End Class
--------
_
Public Shared Function _
RegisterDeviceNotification(ByVal IntPtr As IntPtr, ByVal NotificationFilter As IntPtr, ByVal Flags As Int32) As IntPtr
End Function
--------
Dim dbi As Win32.DEV_BROADCAST_DEVICEINTERFACE = New Win32.DEV_BROADCAST_DEVICEINTERFACE
Dim size As Integer
size = Marshal.SizeOf(dbi)
dbi.dbcc_size = size
dbi.dbcc_devicetype = Win32.DBT_DEVTYP_DEVICEINTERFACE
Dim Buffer As IntPtr
Buffer = Marshal.AllocHGlobal(size)
Marshal.StructureToPtr(dbi, Buffer, True)
Dim r As IntPtr
r = Win32.RegisterDeviceNotification(Handle, Buffer, Win32.DEVICE_NOTIFY_WINDOW_HANDLE)
But when I switch to Xojo, I couldn’t use some functions like Marshal.SizeOf(dbi)
or Marshal.StructureToPtr(dbi, Buffer, True).
Soft Declare Function RegisterDeviceNotificationW Lib "user32" ( handler as Ptr, interfaceFilter As Ptr, flags As Integer) As Ptr
I have trouble when changing a DEV_BROADCAST_DEVICEINTERFACE structure to interfaceFilter Ptr. That is my working:
Dim dbi As DEV_BROADCAST_DEVICEINTERFACE
Dim mb As New MemoryBlock(size)
Dim buffer As Ptr = mb
buffer.DEV_BROADCAST_DEVICEINTERFACE = dbi
Dim result As Ptr = RegisterDeviceNotificationW(AddressOf WndProc, buffer, DEVICE_NOTIFY_WINDOW_HANDLE )
Result is Nil so it’s not working. Could you give me some instruction?
I’m new in Xojo and Windows developer. So it is really hard to study Thanks for your help.
Dim dbi As DEV_BROADCAST_DEVICEINTERFACE
Dim mb As New MemoryBlock(size)
buffer.StringValue(0,size) = dbi.StringValue(false)
Dim result As Ptr = RegisterDeviceNotificationW(AddressOf WndProc, mb, DEVICE_NOTIFY_WINDOW_HANDLE )
Or simply
Dim dbi As DEV_BROADCAST_DEVICEINTERFACE
Dim result As Ptr = RegisterDeviceNotificationW(AddressOf WndProc, dbi, DEVICE_NOTIFY_WINDOW_HANDLE )
I think that different parameters must be specified when calling this function as, for example, the window handle receiving the notification (the 2nd function parameter).
If you can do this already in VB.NET, then perhaps you could do the device notification work in a vb.net helper app. which sends you a TCP/IP message with device change notifications or your own.
@Chris Carter : That’s really a good idea to resolve the problem. Thanks you. But I don’t know how to send TCP/IP message from VB.NET helper app to Xojo app. Could you suggest to me any documents?