⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btdrt.cxx

📁 WinCE5.0部分核心源码
💻 CXX
📖 第 1 页 / 共 2 页
字号:
}

int BthCancelInquiry
(
void
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	return ((DeviceIoControl (hDev, BT_IOCTL_BthCancelInquiry, &bc, sizeof(bc), NULL, NULL, NULL, NULL)) ? ERROR_SUCCESS : GetLastError());
}

int BthTerminateIdleConnections
(
void
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	return ((DeviceIoControl (hDev, BT_IOCTL_BthTerminateIdleConnections, &bc, sizeof(bc), NULL, NULL, NULL, NULL)) ? ERROR_SUCCESS : GetLastError());
}

int BthRemoteNameQuery
(
BT_ADDR			*pba,
unsigned int	cBuffer,
unsigned int	*pcRequired,
WCHAR			*szString
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	bc.BthRemoteNameQuery_p.ba = *pba;
	bc.BthRemoteNameQuery_p.cBuffer = cBuffer;
	bc.BthRemoteNameQuery_p.pcRequired = pcRequired;
	bc.BthRemoteNameQuery_p.pszString = szString;

	return ((DeviceIoControl (hDev, BT_IOCTL_BthRemoteNameQuery, &bc, sizeof(bc), NULL, NULL, NULL, NULL)) ? ERROR_SUCCESS : GetLastError());
}

int BthReadLocalAddr
(
BT_ADDR	*pba
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthReadLocalAddr, &bc, sizeof(bc), NULL, NULL, NULL, NULL);
	if (iErr)
		*pba = bc.BthReadLocalAddr_p.ba;

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}

int BthGetHardwareStatus
(
int	*pStatus
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthGetHardwareStatus, &bc, sizeof(bc), NULL, NULL, NULL, NULL);
	if (iErr)
		*pStatus = bc.BthGetHardwareStatus_p.iHwStatus;

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}

int BthSetPIN
(
BT_ADDR			*pba,
int				cPinLength,
unsigned char	*ppin
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	if ((cPinLength > 16) || (cPinLength < 1))
		return ERROR_INVALID_PARAMETER;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));
	bc.BthSecurity_p.ba = *pba;
	bc.BthSecurity_p.cDataLength = cPinLength;
	memcpy (bc.BthSecurity_p.data, ppin, cPinLength);

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthSetPIN, &bc, sizeof(bc), NULL, NULL, NULL, NULL);

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}

int BthSetLinkKey
(
BT_ADDR			*pba,
unsigned char	*pkey
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));
	bc.BthSecurity_p.ba = *pba;
	memcpy (bc.BthSecurity_p.data, pkey, 16);

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthSetLinkKey, &bc, sizeof(bc), NULL, NULL, NULL, NULL);

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}

int BthGetLinkKey
(
BT_ADDR			*pba,
unsigned char	*pkey
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));
	bc.BthSecurity_p.ba = *pba;

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthGetLinkKey, &bc, sizeof(bc), NULL, NULL, NULL, NULL);

	if (iErr)
		memcpy (pkey, bc.BthSecurity_p.data, 16);

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}

int BthRevokePIN
(
BT_ADDR			*pba
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));
	bc.BthSecurity_p.ba = *pba;

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthRevokePIN, &bc, sizeof(bc), NULL, NULL, NULL, NULL);

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}

int BthRevokeLinkKey
(
BT_ADDR			*pba
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));
	bc.BthSecurity_p.ba = *pba;

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthRevokeLinkKey, &bc, sizeof(bc), NULL, NULL, NULL, NULL);

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}

int BthAuthenticate
(
BT_ADDR			*pba
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));
	bc.BthAuthenticate_p.ba = *pba;

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthAuthenticate, &bc, sizeof(bc), NULL, NULL, NULL, NULL);

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}

int BthSetEncryption
(
BT_ADDR			*pba,
int				fOn
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));
	bc.BthSetEncryption_p.ba = *pba;
	bc.BthSetEncryption_p.fOn = fOn;

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthSetEncryption, &bc, sizeof(bc), NULL, NULL, NULL, NULL);

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}

int BthGetPINRequest
(
BT_ADDR	*pba
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthGetPINRequest, &bc, sizeof(bc), NULL, NULL, NULL, NULL);
	if (iErr)
		*pba = bc.BthGetPINRequest_p.ba;

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}

int BthRefusePINRequest
(
BT_ADDR			*pba
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));
	bc.BthRefusePINRequest_p.ba = *pba;

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthRefusePINRequest, &bc, sizeof(bc), NULL, NULL, NULL, NULL);

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}

int BthAnswerPairRequest 
(
BT_ADDR *pba,
int cPinLength,
unsigned char *ppin
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	if ((cPinLength > 16) || (cPinLength < 1))
		return ERROR_INVALID_PARAMETER;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));
	bc.BthSecurity_p.ba = *pba;
	bc.BthSecurity_p.cDataLength = cPinLength;
	memcpy (bc.BthSecurity_p.data, ppin, cPinLength);

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthAnswerPairRequest, &bc, sizeof(bc), NULL, NULL, NULL, NULL);

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}

int BthPairRequest 
(
BT_ADDR *pba,
int cPinLength,
unsigned char *ppin
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	if ((cPinLength > 16) || (cPinLength < 1))
		return ERROR_INVALID_PARAMETER;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));
	bc.BthSecurity_p.ba = *pba;
	bc.BthSecurity_p.cDataLength = cPinLength;
	memcpy (bc.BthSecurity_p.data, ppin, cPinLength);

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthPairRequest, &bc, sizeof(bc), NULL, NULL, NULL, NULL);

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}

int BthSetSecurityUI
(
HANDLE		hEvent,
DWORD		dwStoreTimeout,
DWORD		dwProcTimeout
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));
	bc.BthSetSecurityUI_p.hEvent = hEvent;
	bc.BthSetSecurityUI_p.dwStoreTimeout = dwStoreTimeout;
	bc.BthSetSecurityUI_p.dwProcessTimeout = dwProcTimeout;

	int iErr = DeviceIoControl (hDev, BT_IOCTL_BthSetSecurityUI, &bc, sizeof(bc), NULL, NULL, NULL, NULL);

	return ((iErr) ? ERROR_SUCCESS : GetLastError());
}


int BthNsSetService(
LPWSAQUERYSET pSet, 
WSAESETSERVICEOP op, 
DWORD dwFlags
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	bc.BthNsSetService_p.pSet    = pSet;
	bc.BthNsSetService_p.op      = op;
	bc.BthNsSetService_p.dwFlags = dwFlags;

	return ((DeviceIoControl(hDev, BT_IOCTL_BthNsSetService,&bc,sizeof(bc),NULL, NULL, NULL, NULL)) ? ERROR_SUCCESS : SOCKET_ERROR);
}

int BthNsLookupServiceBegin(
LPWSAQUERYSET pQuerySet, 
DWORD dwFlags, 
LPHANDLE lphLookup
)  {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	bc.BthNsLookupServiceBegin_p.pQuerySet = pQuerySet;
	bc.BthNsLookupServiceBegin_p.dwFlags   = dwFlags;

	int iErr = DeviceIoControl(hDev, BT_IOCTL_BthNsLookupServiceBegin,&bc,sizeof(bc),NULL, NULL, NULL, NULL);
	if (iErr)
		*lphLookup = bc.BthNsLookupServiceBegin_p.hLookup;

	return ((iErr) ? ERROR_SUCCESS : SOCKET_ERROR);
}

int BthNsLookupServiceNext(
HANDLE hLookup, 
DWORD dwFlags, 
LPDWORD lpdwBufferLength, 
LPWSAQUERYSET pResults
)  {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	bc.BthNsLookupServiceNext_p.hLookup          = hLookup;
	bc.BthNsLookupServiceNext_p.dwFlags          = dwFlags;
	bc.BthNsLookupServiceNext_p.dwBufferLength   = *lpdwBufferLength;
	bc.BthNsLookupServiceNext_p.pResults         = pResults;

	int iErr = DeviceIoControl(hDev, BT_IOCTL_BthNsLookupServiceNext,&bc,sizeof(bc),NULL, NULL, NULL, NULL);
	*lpdwBufferLength = bc.BthNsLookupServiceNext_p.dwBufferLength;

	return ((iErr) ? ERROR_SUCCESS : SOCKET_ERROR);
}

int BthNsLookupServiceEnd(
HANDLE hLookup
)  {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	bc.BthNsLookupServiceEnd_p.hLookup = hLookup;
	return ((DeviceIoControl(hDev, BT_IOCTL_BthNsLookupServiceEnd,&bc,sizeof(bc),NULL, NULL, NULL, NULL)) ? ERROR_SUCCESS : SOCKET_ERROR);
}

int BthSetInquiryFilter
(
BT_ADDR			*pba
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	bc.BthSetInquiry_p.ba = *pba;
	return ((DeviceIoControl(hDev, BT_IOCTL_BthSetInquiryFilter,&bc,sizeof(bc),NULL, NULL, NULL, NULL)) ? ERROR_SUCCESS : GetLastError());
}

int BthClearInquiryFilter
(
void
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	return ((DeviceIoControl(hDev, BT_IOCTL_BthClearInquiryFilter,&bc,sizeof(bc),NULL, NULL, NULL, NULL)) ? ERROR_SUCCESS : GetLastError());
}

int BthCreateACLConnection
(
BT_ADDR			*pbt,
unsigned short	*phandle
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	bc.BthCreateConnection_p.ba = *pbt;

	int iRes = ((DeviceIoControl (hDev, BT_IOCTL_BthCreateACLConnection, &bc, sizeof(bc), NULL, NULL, NULL, NULL)) ? ERROR_SUCCESS : GetLastError());
	if (iRes == ERROR_SUCCESS)
		*phandle = bc.BthCreateConnection_p.handle;

	return iRes;
}

int BthCreateSCOConnection
(
BT_ADDR			*pbt,
unsigned short	*phandle
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	bc.BthCreateConnection_p.ba = *pbt;

	int iRes = ((DeviceIoControl (hDev, BT_IOCTL_BthCreateSCOConnection, &bc, sizeof(bc), NULL, NULL, NULL, NULL)) ? ERROR_SUCCESS : GetLastError());
	if (iRes == ERROR_SUCCESS)
		*phandle = bc.BthCreateConnection_p.handle;

	return iRes;
}

int BthCloseConnection
(
unsigned short	handle
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	bc.BthCloseConnection_p.handle = handle;

	return ((DeviceIoControl (hDev, BT_IOCTL_BthCloseConnection, &bc, sizeof(bc), NULL, NULL, NULL, NULL)) ? ERROR_SUCCESS : GetLastError());
}

int BthAcceptSCOConnections
(
BOOL fAccept
) {
	if (! Initialize())
		return ERROR_SERVICE_NOT_ACTIVE;

	BTAPICALL bc;
	memset (&bc, 0, sizeof(bc));

	bc.BthAcceptSCOConnections_p.fAccept = fAccept;

	return ((DeviceIoControl (hDev, BT_IOCTL_BthAcceptSCOConnections, &bc, sizeof(bc), NULL, NULL, NULL, NULL)) ? ERROR_SUCCESS : GetLastError());
}


extern "C" 
#ifdef UNDER_CE
BOOL WINAPI BthApiDllMain(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved);
#else
BOOL WINAPI BthApiDllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved);
#endif

STDAPI BthApiDllCanUnloadNow(void);
STDAPI BthApiDllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv);
STDAPI BthApiDllRegisterServer(void);
STDAPI BthApiDllUnregisterServer(void);

#ifdef UNDER_CE
BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved)
#else
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
#endif
{
	BOOL fRet = TRUE;
	
	if (g_fBthApiCOM)
		fRet = BthApiDllMain(hInstance,dwReason,lpReserved);

	if (hDev && (DLL_PROCESS_DETACH == dwReason)) {
		CloseHandle(hDev);		
		hDev = NULL;
	}

	return fRet;
}

STDAPI DllCanUnloadNow(void) {
	if (g_fBthApiCOM)
		return BthApiDllCanUnloadNow();

	// If we're not running with sdpuser COM component included, we should never be here.
	SVSUTIL_ASSERT(0);
	return TRUE;
}

STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) {
	if (g_fBthApiCOM)
		return BthApiDllGetClassObject(rclsid, riid,ppv);

	return FALSE;
}

STDAPI DllRegisterServer(void) {
	if (g_fBthApiCOM)
		return BthApiDllRegisterServer();

	return FALSE;
}

STDAPI DllUnregisterServer(void) {
	if (g_fBthApiCOM)
		return BthApiDllUnregisterServer();

	return FALSE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -