How to disconnect a bluetooth device from C# .Net in Win7 -



How to disconnect a bluetooth device from C# .Net in Win7 -

i disconnect bluetooth device c# .net application, runs on win 7 x64.

i know ms provides little functionnality reguarding bt on .net.

i've searched 32feet.net, , found how connect, discover, information, ... nil disconnecting (have missed ?).

then, found on msdn ioctl_bth_disconnect_device. problem can't understand how phone call it. seems shoud utilize deviceiocontrol platform invoke, i'm afraid haven't got plenty .net skills build myself.

here @ moment :

using system; using system.collections.generic; using system.linq; using system.text; using system.runtime.interopservices; using microsoft.win32.safehandles; using system.io; namespace btdisco { class programme { const int ioctl_bth_disconnect_device = 0x41000c; [dllimport("kernel32.dll", setlasterror = false, charset = charset.auto)] public static extern bool deviceiocontrol( microsoft.win32.safehandles.safefilehandle hdevice, uint dwiocontrolcode, [marshalas(unmanagedtype.asany)] [in] object inbuffer, uint ninbuffersize, [marshalas(unmanagedtype.asany)] [out] object outbuffer, uint noutbuffersize, ref uint pbytesreturned, [in] ref system.threading.nativeoverlapped overlapped ); [dllimport("kernel32.dll", setlasterror = true, charset = charset.auto)] static extern safefilehandle createfile( string lpfilename, [marshalas(unmanagedtype.u4)] fileaccess dwdesiredaccess, [marshalas(unmanagedtype.u4)] fileshare dwsharemode, intptr lpsecurityattributes, [marshalas(unmanagedtype.u4)] filemode dwcreationdisposition, [marshalas(unmanagedtype.u4)] fileattributes dwflagsandattributes, intptr htemplatefile); static void main(string[] args) { //http://msdn.microsoft.com/en-us/library/windows/desktop/aa363216(v=vs.85).aspx //hdev = utilize createfile safefilehandle _hdev = createfiler(...); deviceiocontrol(hdev, ioctl_bth_disconnect_device, char[] btaddr, btaddr.length(), result, result.length(), ref getcnt, intptr.zero); } } }

could kind plenty help me finish ?

finally, have got working myself !

i searched bit more in inthehand.net code , understood how create !

here working code (you need inthehand.net if want utilize it):

using system; using system.collections.generic; using system.linq; using system.globalization; using system.text; using inthehand.net; using inthehand.net.bluetooth; using system.runtime.interopservices; namespace btdisco2 { class programme { const int ioctl_bth_disconnect_device = 0x41000c; [dllimport("kernel32.dll", setlasterror = true, charset = charset.auto)] internal static extern bool deviceiocontrol( intptr hdevice, uint dwiocontrolcode, ref long inbuffer, int ninbuffersize, intptr outbuffer, int noutbuffersize, out int pbytesreturned, intptr lpoverlapped); static void main(string[] args) { var r = bluetoothradio.primaryradio; var h = r.handle; long btaddr = bluetoothaddress.parse("00:1b:3d:0d:ac:31").toint64(); int bytesreturned = 0; var success = deviceiocontrol(h, ioctl_bth_disconnect_device, ref btaddr, 8, intptr.zero, 0, out bytesreturned, intptr.zero); if (!success) { int gle = marshal.getlastwin32error(); console.writeline(string.format(cultureinfo.invariantculture, "failure: {0} = 0x{0:x}.", gle)); } else { console.writeline("success !"); } while (!console.keyavailable) system.threading.thread.sleep(200); } } }

c# .net bluetooth pinvoke deviceiocontrol

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -