[急]如何通过蓝牙发送一个文本文件?能解决,给多少分都行!
如何通过蓝牙发送一个文本文件?能解决,给多少分都行!
最好能调用系统的蓝牙模块。
[解决办法]
是沙发吗?好像是!
你描述的不是很清楚,我大概说下。
使用蓝牙通讯可以直接调用winsock访问蓝牙的协议站,就是简单的WSAXXX,send,recv;
另外一种方式是通过蓝牙专用的虚拟串口驱动,用DeviceIoControl访问com驱动,
createfile,writefile,readfile
[解决办法]
最简单的办法是当串口来处理
[解决办法]
蓝牙连上 然后用socket啊 很简单的么 系统的蓝牙模块 好像也有相关的东东
你看看 btdrt这个模块什么的吧
[解决办法]
socket需要一个客户端还需要一个服务器,增加工作量。可以用OBEX
HRESULT ObexHelper::SendFile(IObexDevice *pDevice, const WCHAR *pszPath, HWND hWnd){ HRESULT hr = S_OK; // // Opens the specified file. // FILE *pFile = _wfopen(pszPath, L"r"); if (pFile == NULL) { return E_FILE_NOT_FOUND; } // // Extracts the file name(include extersion). // const WCHAR *pszName = wcsrchr(pszPath, L'\\'); pszName == 0 ? pszName = pszPath : pszName++; IHeaderCollection *pConnectHeaders = 0; hr = CoCreateInstance(__uuidof(HeaderCollection), NULL, CLSCTX_INPROC_SERVER, __uuidof(IHeaderCollection), (void**)&pConnectHeaders); if (FAILED(hr)) { return hr; } if (g_bAbort) { pConnectHeaders->Release(); return E_ABORT; } //if (dwFlags & DEV_SERVICE_FTP) //hr = pConnectHeaders->AddTarget(sizeof(CLSID_FileExchange_NetOrder), (UCHAR*)&CLSID_FileExchange_NetOrder); // // Connects to the remote device. // SendMessage(hWnd, WM_OBEX_INFO, (WPARAM)pDevice, OBEX_INFO_CONNECT); hr = pDevice->Connect(NULL, 0, pConnectHeaders); if (FAILED(hr)) { pConnectHeaders->Release(); SendMessage(hWnd, WM_OBEX_INFO, (WPARAM)pDevice, OBEX_INFO_FAIL); return hr; } if (g_bAbort) { pDevice->Disconnect(pConnectHeaders); pConnectHeaders->Release(); return E_ABORT; } // // Transfer binary data. // SendMessage(hWnd, WM_OBEX_INFO, (WPARAM)pDevice, OBEX_INFO_TRANSFERDATA); IHeaderCollection *pFileHeaders = NULL; hr = CoCreateInstance(__uuidof(HeaderCollection), NULL, CLSCTX_INPROC_SERVER, __uuidof(IHeaderCollection), (void**)&pFileHeaders); if (FAILED(hr)) { pDevice->Disconnect(pConnectHeaders); pConnectHeaders->Release(); SendMessage(hWnd, WM_OBEX_INFO, (WPARAM)pDevice, OBEX_INFO_FAIL); return hr; } if (g_bAbort) { pFileHeaders->Release(); pDevice->Disconnect(pConnectHeaders); pConnectHeaders->Release(); return E_ABORT; } hr = pFileHeaders->AddName(pszName); if (FAILED(hr)) { pFileHeaders->Release(); pDevice->Disconnect(pConnectHeaders); pConnectHeaders->Release(); SendMessage(hWnd, WM_OBEX_INFO, (WPARAM)pDevice, OBEX_INFO_FAIL); return hr; } if (g_bAbort) { pFileHeaders->Release(); pDevice->Disconnect(pConnectHeaders); pConnectHeaders->Release(); return E_ABORT; } IStream *pStream = NULL; hr = pDevice->Put(pFileHeaders, &pStream); if (hr == S_OK) { // // Calculates the size of the file. // fseek(pFile, 0, SEEK_END); LONG iFileSize = ftell(pFile); fseek(pFile, 0, SEEK_SET); char *pszBuffer = new char[PM_LOG_BUFSIZE]; if (pszBuffer == NULL) { pStream->Release(); pFileHeaders->Release(); pDevice->Disconnect(pConnectHeaders); pConnectHeaders->Release(); return E_OUTOFMEMORY; } while (iFileSize > 0) { size_t cbReaded = fread(pszBuffer, 1, PM_LOG_BUFSIZE, pFile); if (cbReaded == 0) { break; } DWORD dwBytesWritten; hr = pStream->Write(pszBuffer, cbReaded, &dwBytesWritten); if (FAILED(hr)) { iFileSize -= cbReaded; continue; } ASSERT(cbReaded == dwBytesWritten); //DWORD dwBytesWrittenTotle = 0; //char *pszTemp = pszBuffer; //while (dwBytesWrittenTotle < cbReaded) //{ // hr = pStream->Write(pszTemp, cbReaded, &dwBytesWritten); // if (FAILED(hr)) // { // break; // } // pszTemp += dwBytesWritten; // dwBytesWrittenTotle += dwBytesWritten; //} iFileSize -= cbReaded; } delete[] pszBuffer; fclose(pFile); pStream->Commit(STGC_DEFAULT); pStream->Release(); } pFileHeaders->Release(); pDevice->Disconnect(pConnectHeaders); pConnectHeaders->Release(); return hr;}
[解决办法]
顶
[解决办法]
学习了,帮顶一下,关注中~
[解决办法]
好贴!
也来顶一下