Showing posts with label detecting. Show all posts
Showing posts with label detecting. Show all posts

Friday, August 19, 2016

CPP Detecting and Connecting Bluetooth Devices

CPP Detecting and Connecting Bluetooth Devices


#include<Windows.h>#include<BluetoothAPIs.h> #pragma comment(lib,"Bthprops.lib") #define pwd TEXT("012345") int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPI, LPSTR lpCL, int iCS) { BLUETOOTH_DEVICE_SEARCH_PARAMS sp; sp.cTimeoutMultiplier = (UCHAR)(1.28*5); sp.dwSize=sizeof(sp); sp.fReturnAuthenticated = false; sp.fIssueInquiry = true; sp.fReturnConnected = true; sp.fReturnRemembered = false; sp.fReturnUnknown = true; sp.hRadio = NULL; BLUETOOTH_DEVICE_INFO di; di.dwSize = sizeof(di); HBLUETOOTH_DEVICE_FIND hB_DF = BluetoothFindFirstDevice(&sp,&di); if(hB_DF=NULL) MessageBox(0,"An Error Occured","Error",0); char* msg =new char; char* res = new char; for(int i=0; i<=BLUETOOTH_MAX_NAME_SIZE; i++) { res[i]=di.szName[i]; res[i+1]=; } wsprintf(msg,"%s",res); MessageBox(0,msg,"Info",0); DWORD result = BluetoothAuthenticateDevice(NULL,NULL,&di,(PWSTR)pwd,(ULONG)wcslen((PWSTR)pwd)); if(result != BTH_ERROR_SUCCESS){ wsprintf(msg,"Error in Authentication! Error Code is: %i",result); MessageBox(0,msg,"Error",MB_OK); return -1; } else { MessageBox(0,"Authenticated","Info",MB_OK); } return 0; }

Go to link download

Read more »