L_InetSetCommandCallback
#include "l_bitmap.h"
#include "ltnet.h"
L_INT EXT_FUNCTION L_InetSetCommandCallback(hComputer, pfnCallback, pUserData)
L_COMP hComputer; |
/* computer to associate the callback data with */ |
INETCALLBACK pfnCallback; |
/* callback to associate */ |
/* user data to associate */ |
Sets the command callback function to use for incoming command requests.
Parameter Description
hComputer |
Handle of the host computer to be associated with the callback. |
pfnCallback |
Pointer to an optional callback. You can pass NULL if you want the default INETCALLBACK to be called when a command request is received. |
pUserData |
Void pointer that can be used to access a variable or structure containing data that the callback function needs. This gives you a way to receive data indirectly from the function that uses this callback. |
|
Keep in mind that this is a void pointer, which must be cast to the appropriate data type within the callback function. |
Returns
SUCCESS |
This function was successful. |
< 1 |
An occurred. Refer to Return Codes. |
Comments
This function sets a specialized callback to handle the incoming command requests. By default, the INETCALLBACK handles the command requests, but INETCALLBACK is not suitable for handling the command parameters and extra data. Use an INETCOMMANDCALLBACK function to process the command requests properly.
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: |
INETCOMMANDCALLBACK, L_InetSetResponseCallback, INETRESPONSECALLBACK |
Topics: |
|
|
Example
/*
This example will create a server and set the command and
response callback
*/
L_COMP ghServer;
// Global bitmap list used to hold the local bitmaps loaded with CMD_LOAD
HBITMAPLIST ghBitmapList;
// Bitmap loaded on the remote computer using L_InetSendCmdLoad
L_UINT guBitmapID; // the bitmap ID which is loaded on the remote
computer
L_COMP ghComputer; // the computer where the bitmap is loaded
L_UINT guWindowID; // the id of the window that is created on the remote
computer
// This can be either the local or the remote computer
//********** Code on the remote computer ****************/
L_INT RemoveBitmap(L_UINT uBitmapID);
L_INT GetLocalBitmap(pBITMAPHANDLE pBitmap, L_UINT uBitmapID);
L_INT AddBitmap(pBITMAPHANDLE pBitmap, L_UINT L_FAR*puBitmapID);
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_TCHAR s[100]; /* set up a buffer to retrieve the name
of the server */
L_UINT32 sizeof_s = sizeof(s); /* the size of s */
switch(nMessage)
{
case INET_CONNECT:
/* check the status and try to get
server's name */
if(nError == SUCCESS)
{
/* now you can assume
you are connected to computer 'hComp' */
if(L_InetGetHostName(hComp,
(L_CHAR) s, HOST_NAME_IP, &sizeof_s) == SUCCESS)
{
MessageBox(NULL,
TEXT("You have successfully connected to"), s, MB_OK);
}
/* do whatever you
want to do with the server here ... */
/* remove the next
line if you want to keep the connection open */
L_InetClose(hComp,
TRUE);
}
else
MessageBox(NULL,
TEXT("You have failed to connect!"), TEXT("Error"),
MB_OK);
break;
}
return SUCCESS;
}
L_INT EXT_CALLBACK InetCommandCallback(L_COMP hComputer,CMDTYPE uCommand, L_UINT uCommandID,L_INT nError, L_UINT uParams,pPARAMETER pParams, L_UINT uExtra,L_CHAR L_FAR *pExtra, L_VOID L_FAR *pUserData)
{
L_INT nStatus = ERROR_FEATURE_NOT_SUPPORTED;
BITMAPHANDLE Bitmap;
L_UINT uBitmapID =
(L_UINT)-1;
COLORREF L_FAR *pColor=NULL;
L_UINT32 lColorSize=0;
if(nError != SUCCESS)
nStatus
= ERROR_TRANSFER_ABORTED;
else
switch(uCommand)
{
case
CMD_LOAD:
// check
the validity of the parameters
if(uParams == 4 && pParams[0].uType
== PARAM_STRING && pParams[1].uType == PARAM_INT32 &&
pParams[2].uType == PARAM_INT32 && pParams[3].uType == PARAM_UINT32)
{
nStatus = L_LoadFile((L_TCHAR*)pParams[0].pValue,
&Bitmap,sizeof(Bitmap), pParams[1].iValue, pParams[2].iValue, pParams[3].iValue,
NULL, NULL, NULL, NULL);
if(nStatus == SUCCESS)
{
//
add the bitmap to the list of currently open bitmaps
nStatus
= AddBitmap(&Bitmap, &uBitmapID);
}
}
else
nStatus = ERROR_INV_PARAMETER;
// invalid parameters
return L_InetSendLoadRsp(hComputer,
uCommandID, uBitmapID, 0, NULL, nStatus);
case CMD_SAVE:
if(uParams == 6 &&
pParams[0].uType == PARAM_STRING && pParams[1].uType == PARAM_UINT32
&& pParams[2].uType == PARAM_INT32 && pParams[3].uType
== PARAM_INT32 && pParams[4].uType == PARAM_INT32 && pParams[5].uType
== PARAM_UINT32)
{
uBitmapID
= pParams[1].uiValue;
nStatus
= GetLocalBitmap(&Bitmap, uBitmapID);
if(nStatus
== SUCCESS)
nStatus
= L_SaveFile((L_TCHAR*)pParams[0].pValue, &Bitmap, pParams[2].iValue,
pParams[3].iValue, pParams[4].iValue, pParams[5].uiValue, NULL, NULL,
NULL);
}
else
nStatus
= ERROR_INV_PARAMETER;
return L_InetSendSaveRsp(hComputer,
uCommandID, 0, NULL, nStatus);
case CMD_FREE_BITMAP:
if(uParams == 1 &&
pParams[0].uType == PARAM_UINT32)
nStatus
= RemoveBitmap(pParams[0].uiValue);
else
nStatus
= ERROR_INV_PARAMETER;
return L_InetSendFreeBitmapRsp(hComputer,
uCommandID, 0, NULL, nStatus);
case CMD_GET_MAGGLASS_DATA:
if(uParams == 5 &&
pParams[0].uType == PARAM_UINT32 && pParams[1].uType == PARAM_UINT32
&& pParams[2].uType == PARAM_USTRING && pParams[3].uType
== PARAM_INT16 && pParams[4].uType == PARAM_INT16)
{
uBitmapID
= pParams[0].uiValue;
nStatus
= GetLocalBitmap(&Bitmap, uBitmapID);
if(nStatus
== SUCCESS)
{
nStatus
= L_InetGetMagGlassData(&Bitmap, &lColorSize, NULL, pParams[2].puValue,
pParams[3].sValue, pParams[4].sValue);
if(nStatus
== SUCCESS)
{
pColor
= GlobalAllocPtr(GHND, lColorSize);
nStatus
= L_InetGetMagGlassData(&Bitmap, &lColorSize, pColor, pParams[2].puValue,
pParams[3].sValue, pParams[4].sValue);
}
}
}
else
nStatus = ERROR_INV_PARAMETER;
L_InetSendGetMagGlassDataRsp
(hComputer, uCommandID, lColorSize, pColor, pParams[1].uiValue, pParams[2].puValue,
pParams[3].sValue, pParams[4].sValue, 0, NULL, nStatus);
if(pColor)
{
GlobalFreePtr(pColor);
pColor=NULL;
}
break;
}
return L_InetSendRsp(hComputer, uCommand, uCommandID,
NULL, nStatus);
}
//********** Code on the local computer ****************/
L_VOID EXT_CALLBACK InetResponseCallback(L_COMP hComputer,CMDTYPE uCommand,
L_UINT uCommandID,L_INT nError, L_INT nStatus,L_UINT uParams, pPARAMETER
pParams, L_UINT uExtra, L_CHAR L_FAR *pExtra,L_VOID L_FAR *pUserData)
{
if(nError != SUCCESS)
{
OutputDebugString(TEXT("An error
has occurred processing the response!"));
return;
}
switch(uCommand)
{
case CMD_LOAD:
if(nStatus == SUCCESS)
{
if(uParams
== 1 && pParams[0].uType == PARAM_UINT32)
{
ghComputer
= hComputer;
guBitmapID
= pParams[0].uiValue;
OutputDebugString(TEXT("Load
SUCCEEDED!"));
}
}
else
OutputDebugString
(TEXT("Load failed!"));
break;
case CMD_CREATE_WIN:
if(nStatus == SUCCESS)
{
if(uParams
== 1 && pParams[0].uType == PARAM_UINT32)
{
//
the window has been created - store the window ID for later use
ghComputer
= hComputer;
guWindowID
= pParams[0].uiValue;
}
OutputDebugString(TEXT("Create
window SUCCEEDED!"));
}
else
OutputDebugString
(TEXT("Create Window failed"));
break;
case CMD_FREE_BITMAP:
if(nStatus == SUCCESS)
OutputDebugString(TEXT("Free
bitmap SUCCEEDED!"));
else
OutputDebugString
(TEXT("Free bitmap failed"));
break;
}
}
L_INT StartServer()
{
L_INT nRet;
nRet = L_InetServerInit(1000,&ghServer,InetCallback,NULL);
if(nRet==SUCCESS)
{
L_InetSetCommandCallback(ghServer,
InetCommandCallback, NULL);
L_InetSetResponseCallback(ghServer,
InetResponseCallback, NULL);
}
return nRet;
}
/*
The local bitmaps are identified by the index in the bitmap list.
*/
L_INT AddBitmap(pBITMAPHANDLE pBitmap, L_UINT L_FAR*puBitmapID)
{
L_INT nRet;
if(!ghBitmapList)
{
nRet = L_CreateBitmapList(&ghBitmapList);
if(nRet != SUCCESS)
{
L_FreeBitmap(pBitmap);
return nRet;
}
}
nRet = L_InsertBitmapListItem(ghBitmapList, (L_UINT)-1,
pBitmap);
if(nRet == SUCCESS)
L_GetBitmapListCount(ghBitmapList,
puBitmapID);
else
// free the bitmap if an error occurs
because the caller is not doing anything else with it
L_FreeBitmap(pBitmap);
return nRet;
}
L_INT GetLocalBitmap(pBITMAPHANDLE pBitmap, L_UINT uBitmapID)
{
if(ghBitmapList)
return L_GetBitmapListItem(ghBitmapList,
uBitmapID, pBitmap, sizeof(pBitmap));
return ERROR_INV_PARAMETER;
}
L_INT RemoveBitmap(L_UINT uBitmapID)
{
L_INT nRet = ERROR_INV_PARAMETER;
if(ghBitmapList)
{
nRet = L_DeleteBitmapListItems(ghBitmapList,
uBitmapID, 1);
if(nRet == SUCCESS)
{
// Go to all the
places that you might have used this bitmap and make the
// necessary changes
}
}
return nRet;
}