Function – QueryBus

QueryBus sends request to get complete information from the virtual serial bus installed by VSPD.

BOOL QueryBus(
	void* inBuffer, 	// pointer to buffer
	long sizeInBuffer, 	// size of buffer
	void* OutBuffer, 	// pointer to buffer
	long sizeOutBuffer, 	// size of buffer
);

Parameters:

QueryType IN OUT
QUERYTYPE_PORTS VSBUS_QUERY PORT_INFORMATION
QUERYTYPE_PORTS2 VSBUS_QUERY PORT_SHORT_EX2
QUERYINFO_PAIR VSBUS_QUERY_EX PORT_INFORMATION_EX
QUERYINFO_PAIR2 VSBUS_QUERY_EX PORT_INFORMATION_EX2
QUERYINFO_PAIR3 VSBUS_QUERY_EX2 PORT_INFORMATION_EX3

Return values : CreatePair returns TRUE if virtual serial pair was created successfully and FALSE otherwise.


Code examples:

Getting information about all virtual serial ports:

void		*Buffer;
long		sizeBuffer;

Query.Size = sizeof (VSBUS_QUERY);
Query.QueryType = QUERYTYPE_PORTS;
Buffer = new char[sizeBuffer];

	while (!QueryBus(&Query, Query.Size, Buffer, sizeBuffer)) {

	if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
		{
			delete[] Buffer;
			return;

		}
		else
		  {
			delete[] Buffer;
			   sizeBuffer = sizeBuffer * 2;			
			   Buffer = new char[sizeBuffer];
		}
}

PPORT_INFORMATION	portInfo = (PPORT_INFORMATION)Buffer;

while (portInfo->NextOffset != 0) 
	{
		if (portInfo->NameOffset != 0)
		{
			CString portName((PWCHAR)((ULONG)portInfo + portInfo->NameOffset));
			printf ("%s\n", portName);
		}

		portInfo = (PPORT_INFORMATION)((ULONG)portInfo + portInfo->NextOffset);
	} 
delete[] Buffer;

Getting information about a single port:

void		*Buffer;
int		iSize = 1024;
VSBUS_QUERY_EX	Query;
PPORT_INFORMATION_EX portInfo;

Query.Size = sizeof (VSBUS_QUERY_EX);
Query.QueryType = QUERYINFO_PAIR;
mbstowcs (Query.PortName, "COM5", MAX_PORTNAME_LEN);

Buffer = new char [iSize];

while (!QueryBus(&Query, Query.Size, Buffer, iSize)) {
	{
		if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
		{
			delete[] Buffer;
			   return;
		}
		else
		{
			iSize *= 2;
			delete[] Buffer;
		    Buffer = new char [iSize];
		}
	}

while (portInfo->NextOffset != 0) 
{
	if (portInfo->NameOffset != 0) 
	{
		CString portName((PWCHAR)((ULONG)portInfo + portInfo->NameOffset));
		printf ("%s send - %d recv - %d\n", portName, portInfo->TxCount, portInfo->RxCount);
	}

	portInfo = (PPORT_INFORMATION_EX)((ULONG)portInfo + portInfo->NextOffset);
} 

portInfo = (PPORT_INFORMATION_EX)Buffer;
delete[] Buffer;