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

📄 irdasocket.h

📁 WINCE下 红外遥控设备程序
💻 H
字号:
//////////////////////////////////////////////////////////////////////////
//
//  IrDASocket.h - IrDA socket support for Pocket PC
//
//  Written by Daniel Strigl (daniel.strigl@web.de).
//  Copyright (c) 2003. All Rights Reserved.
//
//  The original code was written by Ramon de Klein (R.de.Klein@iaf.nl).
//
//  The original IrDA socket support class can be found in
//  the "Bubbles for Pocket PC" application from Ramon de Klein
//  at http://www.codeproject.com/ce/bubbles.asp or
//  http://home.ict.nl/~ramklein/Projects/Bubbles.html.
//
//  Feel free to modify the source code and / or use it in your
//  own programs. By the way, I would appreciate and enjoy hearing
//  about them (just send an e-mail to daniel.strigl@web.de).
//
//  Please report any bug, comment, suggestion, etc. to the
//  following address: daniel.strigl@web.de
//
//  Contact:
//  --------
//
//    Daniel Strigl
//    daniel.strigl@web.de
//    http://www.hh-system.com/danielstrigl
//
//  History:
//  --------
//
//    02.04.2003: The original IrDA socket support class was written
//                to use in ATL/WTL applications. Modified the class
//                so that it can be used in every MFC application.
//
//    03.04.2003: Added the "VerifyService" function.
//
//    16.04.2003: Added a second "VerifyService" function and modified
//                the original "VerifyService" function.
//
//  ORIGINAL COPYRIGHT STATEMENTS:
//  ------------------------------
//
//    IrDASocket.h - Bubbles for Pocket PC (IrDA socket support)
//
//    Copyright (C) 2000 Ramon de Klein (R.de.Klein@iaf.nl)
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program; if not, write to the Free Software
//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//////////////////////////////////////////////////////////////////////////

#ifndef __IRDASOCKET_H__
#define __IRDASOCKET_H__

//////////////////////////////////////////////////////////////////////////
// Includes

#include <winsock.h>
#include <af_irda.h>

//////////////////////////////////////////////////////////////////////////
// CWinSock class

class CWinSock
{
private:
	static int     mg_iInstance;
	static WSADATA mg_wsaData;

public:
	CWinSock();
	~CWinSock();
};

//////////////////////////////////////////////////////////////////////////
// CIrDASocket class

class CIrDASocket
{
private:
	SOCKET m_sd;

public:
	CIrDASocket();
	~CIrDASocket();

	bool WaitForOperation(const bool fRead, const bool fWrite, const DWORD dwTimeout);
	bool EnumDevices(DEVICELIST* pDevList, int cbDevices);
    bool VerifyService(PIAS_QUERY pIASQuery, int iasqlen=sizeof(IAS_QUERY));
    bool VerifyService(const LPBYTE pDeviceId, LPCSTR lpszClassName);
	bool Open();
	bool Close();
	bool Bind(LPCSTR lpszServiceName);
	bool Listen(const int iBackLog=1);
	bool Accept(SOCKET* psd, const DWORD dwTimeout);
	bool Connect(LPCSTR lpszServiceName, const LPBYTE pDeviceId, const DWORD dwTimeout);
	bool Send(LPCVOID lpData, DWORD cbBytes, const DWORD dwTimeout);
	bool Receive(LPVOID lpData, DWORD cbBytes, const DWORD dwTimeout);

	template <class T>
    bool Send(const T& data, const DWORD dwTimeout)
	{
		return Send(&data,sizeof(T),dwTimeout);
	}

	template <class T>
    bool Receive(T& data, const DWORD dwTimeout)
	{
		return Receive(&data,sizeof(T),dwTimeout);
	}

	operator SOCKET()
	{
		return m_sd;
	}

	SOCKET* operator& ()
	{
		ASSERT(m_sd == INVALID_SOCKET);
		return &m_sd;
	}
};

//////////////////////////////////////////////////////////////////////////

#endif // __IRDASOCKET_H__

⌨️ 快捷键说明

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