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

📄 bthhelper.cpp

📁 windows CE 一些有用的源代码 比如camera
💻 CPP
字号:
// BthHelper.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>

#include <winsock2.h>
#include <bt_api.h>

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    return TRUE;
}



extern "C" bool PopulateBtDevList(HWND hDlg )
{
	WORD wVersionRequested;
	WSADATA wsaData;
	
	// Initialize Winsock
	wVersionRequested = MAKEWORD( 2, 2 );
	
	if (!WSAStartup( wVersionRequested, &wsaData ) == 0)
	{
		MessageBox(NULL, _T("Could not initialize winsock!"), _T("Fatal Error"), MB_OK);
		return false;
	}
	
	INT				iResult = 0;
	LPWSAQUERYSET	pwsaResults;
	DWORD			dwSize = 0;
	WSAQUERYSET		wsaq;
	HCURSOR			hCurs;
	HANDLE			hLookup = 0;
	
	
	memset (&wsaq, 0, sizeof(wsaq));
	wsaq.dwSize      = sizeof(wsaq);
	wsaq.dwNameSpace = NS_BTH;
	wsaq.lpcsaBuffer = NULL;
	
	// initialize searching procedure
	iResult = WSALookupServiceBegin(&wsaq, 
		LUP_CONTAINERS, 
		&hLookup);
	
	if (iResult != 0)
	{
		TCHAR tszErr[32];
		iResult = WSAGetLastError();		
		StringCchPrintf(tszErr, 32, _T("Socket Error: %d"), iResult);
		MessageBox(hDlg, tszErr, _T("Error"), MB_OK);
		
		return false;
	}
	
	union {
		CHAR buf[5000];				// returned struct can be quite large 
		SOCKADDR_BTH	__unused;	// properly align buffer to BT_ADDR requirements
	};
	
	for (; ;)
	{
		pwsaResults = (LPWSAQUERYSET) buf;
		
		dwSize  = sizeof(buf);
		
		memset(pwsaResults,0,sizeof(WSAQUERYSET));
		pwsaResults->dwSize      = sizeof(WSAQUERYSET);
		// namespace MUST be NS_BTH for bluetooth queries
		pwsaResults->dwNameSpace = NS_BTH;
		pwsaResults->lpBlob      = NULL;
		
		// iterate through all found devices, returning name and address
		// (this sample only uses the name, but address could be used for
		// further queries)
		iResult = WSALookupServiceNext (hLookup, 
			LUP_RETURN_NAME | LUP_RETURN_ADDR, 
			&dwSize, 
			pwsaResults);
		
		
		if (iResult != 0)
		{
			iResult = WSAGetLastError();
			if (iResult != WSA_E_NO_MORE)
			{
				TCHAR tszErr[32];
				iResult = WSAGetLastError();
				StringCchPrintf(tszErr, 32, _T("Socket Error: %d"), iResult);
				MessageBox(hDlg, tszErr, _T("Error"), MB_OK);
			}
			// we're finished

			return false;
		}
		
		// add the name to the listbox
		if (pwsaResults->lpszServiceInstanceName)
		{
			SendMessage(hDlg, 
				WM_USER+101, 
				0, 
				(LPARAM)pwsaResults->lpszServiceInstanceName);
		}
		
	}
	
	WSALookupServiceEnd(hLookup);
	
	return true;
}

⌨️ 快捷键说明

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