Click here to Skip to main content
15,887,214 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Thanks Pin
Jaime Stuardo3-Aug-04 14:20
Jaime Stuardo3-Aug-04 14:20 
GeneralRe: Thanks Pin
0v3rloader3-Aug-04 23:09
0v3rloader3-Aug-04 23:09 
GeneralRe: CDatabase && CRecordSet Pin
Michael P Butler4-Aug-04 0:12
Michael P Butler4-Aug-04 0:12 
GeneralMFC CSockets Pin
pork chop3-Aug-04 6:39
pork chop3-Aug-04 6:39 
GeneralRe: MFC CSockets Pin
palbano3-Aug-04 9:39
palbano3-Aug-04 9:39 
QuestionHow to open an specific view? Pin
Ivan Cachicatari3-Aug-04 6:14
Ivan Cachicatari3-Aug-04 6:14 
AnswerRe: How to open an specific view? Pin
Roger Allen3-Aug-04 6:44
Roger Allen3-Aug-04 6:44 
GeneralWeird Irda problem and abnormally increasing HANDLE count... Pin
3-Aug-04 5:25
suss3-Aug-04 5:25 
<br />
/*<br />
 *<br />
 * Weird Irda problem and abnormally increasing HANDLE count...<br />
 * <br />
 * Two major problems in the code:<br />
 *<br />
 *   If the program starts from the strach and Irda device is in range and active<br />
 *   it finds it. But if the program has already been started, and the same Irda<br />
 *   device again is active and in range, cannot find it.<br />
 *<br />
 *   Why is it So(S?)<br />
 *<br />
 *   Another problem is, the HANDLE count of the program continuosly increasing.<br />
 *   I'm thinking that the problem is on the Winsock socket creation routine<br />
 *   but I also don't know ıf there any mechanism to give the socket handle back <br />
 *   to OS.<br />
 *<br />
 *   Thanks a lot.<br />
 *<br />
 */<br />
<br />
#include "Utility.h"<br />
#include <Af_irda.h><br />
<br />
#define IRDA_DEVICE_LIST_LEN    16<br />
#define IRDA_TRY_COUNT			30<br />
#define IRDA_TRY_SLEEP_MSEC		1000<br />
<br />
int				DevListLen = sizeof(DEVICELIST) <br />
								* IRDA_DEVICE_LIST_LEN;<br />
<br />
int				EnumTest(void);<br />
PDEVICELIST		EnumIrdaDevices(void);<br />
BOOL			EnumIrdaDevicesTest(void);<br />
<br />
int ExecuteIrdaEnumTest(void)<br />
{<br />
	int result;<br />
	result = EnumIrdaDevicesTest();<br />
<br />
	return result;<br />
}<br />
<br />
int EnumIrdaDevicesTest(void)<br />
{<br />
	int				iDeviceCount;<br />
	PDEVICELIST		pDevList;<br />
<br />
	int				iTryCount = 0;<br />
	int				iDeviceIndex = 0;<br />
<br />
	char*			scs = "|/-\\|/-\\";						// Used while scanning ascii-anim<br />
	short			scsLen = (short)strlen(scs);<br />
	int				schrIndex = 0;<br />
<br />
	printf("Searching for infra-red devices in range... ");<br />
	for (; iTryCount < IRDA_TRY_COUNT; iTryCount++)<br />
	{<br />
		if ((pDevList = EnumIrdaDevices()) != NULL)<br />
			break;<br />
<br />
		schrIndex %= scsLen;<br />
		printf("\b%c", scs[schrIndex++]);<br />
<br />
		free(pDevList);<br />
		Sleep(IRDA_TRY_SLEEP_MSEC);<br />
	}<br />
<br />
	if (pDevList)<br />
	{<br />
		printf("\n\n#%u device(s) has been found, enumerating...\n\n", pDevList->numDevice);<br />
		iDeviceCount = (int)pDevList->numDevice;<br />
		for (; iDeviceIndex < iDeviceCount; iDeviceIndex++)<br />
		{<br />
			printf("Device Info #%u :\n", (iDeviceIndex + 1));<br />
			printf("  Name: %s\n\n"		, pDevList->Device[iDeviceIndex].irdaDeviceName);<br />
		}<br />
	}<br />
	<br />
	free(pDevList);<br />
	return (pDevList != NULL) <br />
		? BE_SUCCESS<br />
		: BE_ERROR;<br />
}<br />
<br />
PDEVICELIST EnumIrdaDevices(void)<br />
{<br />
	int			iResult;<br />
	u_long		index = 0;<br />
	SOCKET		sock;<br />
	PDEVICELIST	pDevList;<br />
<br />
	sock = WSASocket(AF_IRDA, SOCK_STREAM, 0, NULL, 0, <br />
		WSA_FLAG_OVERLAPPED);<br />
<br />
	//<br />
	// I have allocated the variable in here, when I used it<br />
	// as an argument to this function, it sets the address of the<br />
	// pointer to 0x0 when the function returns, why?? I tried hard<br />
	// but couldn't found, even I'm not returning a local var...<br />
	//<br />
	pDevList = (PDEVICELIST) malloc(sizeof(DEVICELIST) * DevListLen);<br />
	<br />
	pDevList->numDevice = 0;<br />
	iResult = getsockopt(sock, SOL_IRLMP, IRLMP_ENUMDEVICES, <br />
		(char *)pDevList, &DevListLen);<br />
<br />
//	return ((pDevList->numDevice > 0) ? TRUE : FALSE);<br />
<br />
	if (pDevList->numDevice > 0)<br />
		return pDevList;<br />
	else<br />
	{<br />
		free(pDevList);<br />
		pDevList = 0;<br />
		return NULL;<br />
	}<br />
}<br />


your life is what you believe
GeneralRe: Weird Irda problem and abnormally increasing HANDLE count... Pin
Trollslayer3-Aug-04 6:40
mentorTrollslayer3-Aug-04 6:40 
GeneralQuestion Pin
rfixxxer3-Aug-04 5:23
rfixxxer3-Aug-04 5:23 
GeneralRe: Question Pin
jmkhael3-Aug-04 5:39
jmkhael3-Aug-04 5:39 
GeneralRe: Question Pin
Michael P Butler3-Aug-04 5:40
Michael P Butler3-Aug-04 5:40 
GeneralRe: Question Pin
rfixxxer3-Aug-04 6:04
rfixxxer3-Aug-04 6:04 
GeneralRe: Question Pin
David Crow3-Aug-04 5:47
David Crow3-Aug-04 5:47 
GeneralRe: Question Pin
rfixxxer3-Aug-04 6:07
rfixxxer3-Aug-04 6:07 
QuestionTransparent button control over a dialog in WinCE ? Pin
Arun AC3-Aug-04 5:19
Arun AC3-Aug-04 5:19 
GeneralNotification popup Pin
Riderman373-Aug-04 4:37
Riderman373-Aug-04 4:37 
GeneralRe: Notification popup Pin
valikac3-Aug-04 5:48
valikac3-Aug-04 5:48 
GeneralRe: Notification popup Pin
David Crow3-Aug-04 5:51
David Crow3-Aug-04 5:51 
GeneralSending an interrupt to a process Pin
Member 6256663-Aug-04 4:23
Member 6256663-Aug-04 4:23 
GeneralRe: Sending an interrupt to a process Pin
jmkhael3-Aug-04 5:18
jmkhael3-Aug-04 5:18 
GeneralLocating chars in strings etc. Pin
CreepingFeature3-Aug-04 4:16
CreepingFeature3-Aug-04 4:16 
GeneralRe: Locating chars in strings etc. Pin
Nigel Savidge3-Aug-04 4:55
Nigel Savidge3-Aug-04 4:55 
GeneralRe: Locating chars in strings etc. Pin
CreepingFeature3-Aug-04 7:08
CreepingFeature3-Aug-04 7:08 
GeneralRe: Locating chars in strings etc. Pin
David Crow3-Aug-04 5:56
David Crow3-Aug-04 5:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.