Antonio Linares wrote:Arturo,
Haz una búsqueda en estos foros por IRDA (botón "search" arriba) y encontrarás muchos comentarios que se han hecho de ese tema, gracias
Antonio:
He leído ya cada uno de los distintos protocolos disponibles para IRDA. Hasta donde he podido entender el código siguiente debe funcionar. Sólo necesitaría de tu ayuda para ponerlo de manera adecuada usando las sentencias de BEGIN..PRAGMA dump.
Saludos. He Aquí:
---------------------------
// Tomado de
//
http://www.pocketpcjunkies.com/Uwe/Foru ... nting-FREE
// By Kevin
BOOL CWarehouseClientApp::IrDAPrint(CString tText)
{
SOCKET sock; // Socket bound to the server
DEVICELIST devList; // Device list
int iCount = 0, // Number of retries
index = 0, // Integer index
iDevListLen = sizeof(devList); // Size of the device list
TCHAR szError[100]; // Error message string
WSADATA wsaData;
WORD wVersion = MAKEWORD(1,1); // Winsock Version 1.1
BYTE IASQueryBuff[sizeof(IAS_QUERY) - 3 + IAS_MAX_ATTRIBNAME];
int IASQueryLen = sizeof(IASQueryBuff);
PIAS_QUERY pIASQuery = (PIAS_QUERY) &IASQueryBuff;
char szServiceName[12];
SOCKADDR_IRDA iraddr;
linger l;
// -------------------------------------------------
if(WSAStartup(wVersion, &wsaData) != 0)
{
wsprintf(szError, TEXT("WSAStartup failed. Error: %d"),
WSAGetLastError());
AfxMessageBox(szError, MB_OK);
return FALSE;
}
// Create a socket that is bound to the server.
if((sock = socket(AF_IRDA, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
wsprintf(szError, TEXT("Allocating socket failed. Error: %d"),
WSAGetLastError());
AfxMessageBox(szError, MB_OK);
WSACleanup();
return FALSE;
}
// Initialize the number of devices to zero.
devList.numDevice = 0;
while((devList.numDevice == 0) && (iCount <= NUMRETRY))
{
// Retrieve the socket option
if(getsockopt(sock, SOL_IRLMP, IRLMP_ENUMDEVICES, (char *)&devList,
&iDevListLen) == SOCKET_ERROR)
{
wsprintf(szError, TEXT("Server could not be located, getsockopt failed.
Error: %d"), WSAGetLastError());
AfxMessageBox(szError, MB_OK);
closesocket(sock);
WSACleanup();
return FALSE;
}
if(devList.numDevice == 0)
{
iCount++;
Sleep(1000);
}
}
if(iCount > NUMRETRY)
{
AfxMessageBox(TEXT("Server could not be located!"), MB_OK);
closesocket(sock);
WSACleanup();
return FALSE;
}
// ------------------------------------------------
memcpy(&pIASQuery->irdaDeviceID, devList.Device[0].irdaDeviceID, 4);
memcpy(&pIASQuery->irdaClassName, "IrLPT", 6);
memcpy(&pIASQuery->irdaAttribName, "IrDA:IrLMP:LsapSel", 19);
if (getsockopt(sock, SOL_IRLMP, IRLMP_IAS_QUERY, (char *)pIASQuery,
&IASQueryLen) == SOCKET_ERROR)
{
wsprintf(szError, TEXT("getsockopt failed. Error: %d"),
WSAGetLastError());
AfxMessageBox(szError, MB_OK);
closesocket(sock);
WSACleanup();
return FALSE;
}
sprintf(szServiceName, "LSAP-SEL%d",
pIASQuery->irdaAttribute.irdaAttribInt);
memset(&iraddr, 0, sizeof(iraddr));
iraddr.irdaAddressFamily = AF_IRDA;
memcpy (iraddr.irdaDeviceID, devList.Device[0].irdaDeviceID, 4);
memcpy (iraddr.irdaServiceName, szServiceName, strlen(szServiceName) + 1);
// Establish a connection to the socket.
if(connect(sock, (struct sockaddr *)&iraddr, sizeof(iraddr)) ==
SOCKET_ERROR )
{
wsprintf(szError, TEXT("Connecting to the server failed. Error: %d"),
WSAGetLastError());
AfxMessageBox(szError, MB_OK);
closesocket(sock);
WSACleanup();
return FALSE;
}
// Turn on SO_LINGER
l.l_onoff = 1;
l.l_linger = 0;
if(setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(struct
linger)) == SOCKET_ERROR )
{
wsprintf(szError, TEXT("setsockopt failed. Error: %d"),
WSAGetLastError());
AfxMessageBox(szError, MB_OK);
closesocket(sock);
WSACleanup();
return FALSE;
}
// Send a string from the client socket to the server socket.
char * aText = StringUtil::ConvertCStringToCharPtr(tText);
if(send(sock, aText, tText.GetLength() + 1, 0) == SOCKET_ERROR)
{
free(aText);
wsprintf(szError, TEXT("Sending data to the server failed. Error: %d"),
WSAGetLastError());
AfxMessageBox(szError, MB_OK);
closesocket(sock);
WSACleanup();
return FALSE;
}
free(aText);
// Close the socket.
if(closesocket(sock) == SOCKET_ERROR)
{
wsprintf(szError, TEXT("closesocket failed. Error: %d"),
WSAGetLastError());
AfxMessageBox(szError, MB_OK);
WSACleanup();
return FALSE;
}
//
WSACleanup();
return TRUE;
}
BOOL CWarehouseClientApp::NetworkPrint(CString tText, CString tPrinterShare)
{
//
BOOL aRetVal = TRUE;
// create file name
CString aFileName = _T("\\Temp\\report.prn");
// open the file
FILE *aFile = NULL;
aFile = _tfopen(aFileName, _T("wt"));
//
if(aFile == NULL)
{
aRetVal = FALSE;
}
else
{
// put the text
_fputts(tText, aFile);
// close the file
fclose(aFile);
// copy file to network share
if(CopyFile(aFileName, tPrinterShare, FALSE) == FALSE)
{
AfxMessageBox(_T("Failed to Print to Network Shared Printer"),
MB_ICONEXCLAMATION);
aRetVal = FALSE;
}
}
//
return aRetVal;
}