L_InetReadData
#include "l_bitmap.h"
#include "ltnet.h"
L_INT EXT_FUNCTION L_InetReadData(hComputer, pBuffer, pulBufferLength)
L_COMP hComputer; |
/* handle of remote computer */ |
/* pointer to the data buffer */ | |
/* address of length of buffer */ |
Reads data from a remote computer.
Parameter |
Description |
hComputer |
Handle of the remote computer from which data is being sent. |
pBuffer |
Address of the buffer to be filled with the read data |
pulBufferLength |
Address of the variable to be updated with the size of the read data |
Returns
SUCCESS |
The function was successful. |
< 1 |
An error occurred. Refer to Return Codes. |
Comments
After this function returns, pulBufferLength will be updated with the actual length of read data. This function should only be used if auto process is disabled. You should call this function in response to the INET_DATA_READY message, in the INETCALLBACK function.
You must initialize the LEADTOOLS Internet DLL using L_InetStartUp before calling this function.
Required DLLs and Libraries
LTNET For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application |
See Also
Functions: |
L_InetAutoProcess, L_InetSendData, L_InetSendBitmap, L_InetSendSound, L_InetConnect, L_InetClose, L_InetReadData, L_InetServerInit, INETCALLBACK, L_InetStartUp, L_InetShutDown |
Topics: |
Example
L_COMP hComp; /* handle of the remote computer */
L_INT nRet;
L_INT L_EXPORT EXT_CALLBACK InetCallback(L_COMP hComp,
L_INT nMessage, L_INT nError, L_CHAR L_FAR *pBuffer,
L_UINT32 lSize,L_VOID L_FAR*pUserData);
/* note: instead of server_address you need to put the IP
address
of the computer running the server. You can also put in
the computer name, if the server is running on a local network */
/* you do not need to use MakeProcInstance for 32 bit applications */
nRet = L_InetConnect("server_address",
1000, &hComp, InetCallback, NULL);
if(nRet != SUCCESS)
MessageBox(NULL, TEXT("Error attempting to connect"),
TEXT("ERROR"), MB_OK);
/*
sometime before closing down the program call L_InetClose(hComp, TRUE)
*/
L_INT L_EXPORT EXT_CALLBACK InetCallback(L_COMP hComp,
L_INT nMessage, L_INT nError, L_CHAR L_FAR *pBuffer,
L_UINT32 lSize,L_VOID L_FAR*pUserData)
{
L_INT nRet;
HGLOBAL hData;
L_CHAR L_FAR*pData;
switch(nMessage)
{
case INET_CONNECT:
/* check the status
and send some data */
if(nError == SUCCESS)
{
/*
set auto process to False to receive INET_DATA_READY */
L_InetAutoProcess(hComp,
FALSE);
}
else
MessageBox(NULL,
TEXT("You have failed to connect!"), TEXT("Error"),
MB_OK);
break;
case INET_DATA_READY:
/* Note: most servers
(including a LEAD server started with
L_InetServerInit
will send some form of data right after connection) */
if(nError == SUCCESS)
{
hData
= GlobalAlloc(GHND, lSize + 1);
pData
= (L_CHAR L_FAR*)GlobalLock(hData);
if(pData)
{
nRet
= L_InetReadData(hComp, pData,
&lSize);
pData[lSize]
= 0; /* make the data NULL-terminated */
MessageBox(NULL,
(L_TCHAR*)pData, TEXT("Data received"), MB_OK);
GlobalUnlock(hData);
}
GlobalFree(hData);
break;
}
}
return SUCCESS;
}