home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
ipxrcv.exe
/
IPXREC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-25
|
16KB
|
416 lines
/*
Copyright (c) 1992 Novell, Inc. All Rights Reserved.
THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
TREATIES. USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE
LICENSE AGREEMENT ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT (SDK)
THAT CONTAINS THIS WORK.
Pursuant to the SDK License Agreement, Novell hereby grants to
Developer a royalty-free, non-exclusive license to include the
sample code IPXREC.C and derivative binaries in its product.
Novell grants to Developer worldwide distribution rights to market,
distribute or sell the sample code IPXREC.C and derivative
binaries as a component of Developer's product(s). Novell shall
have no obligations to Developer or Developer's customers with
respect to this code.
DISCLAIMER:
Novell, Inc. makes no representations or warranties with respect
to the contents or use of this code, and specifically disclaims any
express or implied warranties of merchantability or fitness for any
particular purpose. Further, Novell, Inc. reserves the right to revise
this publication and to make changes to its content, at any time,
without obligation to notify any person or entity of such revisions or
changes.
Further, Novell, Inc. makes no representations or warranties with
respect to any software, and specifically disclaims any express or
implied warranties of merchantability or fitness for any particular
purpose. Further, Novell, Inc. reserves the right to make changes to
any and all parts of the software, at any time, without obligation to
notify any person or entity of such changes.
***************************************************************************
IPXREC.C
**************************************************************************/
/**************************************************************************
** Description: Sample code that demonstrates the how to set up to receive
** an IPX packet within Windows. The partner program to this
** one is IPXSND.
** Compiler: MSC Visual C++ v1.51 for 'C' code.
** MASM v6.00 for 'ASM' code.
**
** Programmer : Karl Bunnell
** Date: 08/24/1995
**
*/
#include <windows.h> /* required for all Windows applications */
#include <stdlib.h>
#include <mmsystem.h>
#include <string.h>
#define NWWIN
#define BIG_MEMORY
#define PROTOTYPE
#define WINDOWS
#include <nwcalls.h>
#include "nxtw.h"
#include "ipxrec.h" /* specific to this program */
#include <ctype.h>
#define MAX_NUMBER_MESSAGES 50
void SizeTheWindow (short *, short *, short *, short *) ;
void WndPaint (HWND, HDC) ;
HANDLE hInst; /* current instance */
HWND myWinHandle;
WORD socket = 0x0000;
WORD MySegment;
HCURSOR hSaveCursor; /* handle to current cursor */
HCURSOR hHourGlass; /* handle to hourglass cursor */
ECB listenECB[MAX_LISTEN_ECBS];
IPXHeader IPXReceive[MAX_LISTEN_ECBS];
DISPLAYDATA displayData[MAX_LISTEN_ECBS];
DWORD IPXTaskID = 0x00000000;
IPXAddress myNetAddr;
static char displayMessage[1024];
static char processMessage[1024];
TEXTMETRIC tm;
/****************************************************************************
FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
PURPOSE: calls initialization function, processes message loop
****************************************************************************/
int PASCAL WinMain(
HANDLE hInstance, /* current instance */
HANDLE hPrevInstance, /* previous instance */
LPSTR lpCmdLine, /* command line */
int nCmdShow) /* show-window type (open/icon) */
{
MSG msg; /* message */
int sizeOfQueue;
BOOL bQueueCreated;
sizeOfQueue = MAX_NUMBER_MESSAGES;
while( ( sizeOfQueue > 0 ) && ( !bQueueCreated ) )
{
bQueueCreated = SetMessageQueue( sizeOfQueue );
sizeOfQueue--;
}
if( sizeOfQueue == 0 )
return( NULL );
lpCmdLine = lpCmdLine;
if (!hPrevInstance) /* Other instances of app running? */
if (!InitApplication(hInstance)) /* Initialize shared things */
return (FALSE); /* Exits if unable to initialize */
if (!InitInstance(hInstance, nCmdShow))
return (FALSE);
/* Acquire and dispatch messages until a WM_QUIT message is received. */
while (GetMessage(&msg, /* message structure */
NULL, /* handle of window receiving the message */
0, /* lowest message to examine */
0)) /* highest message to examine */
{
TranslateMessage(&msg); /* Translates virtual key codes */
DispatchMessage(&msg); /* Dispatches message to window */
}
return (msg.wParam); /* Returns the value from PostQuitMessage */
}
/****************************************************************************
FUNCTION: InitApplication(HANDLE)
PURPOSE: Initializes window data and registers window class
****************************************************************************/
BOOL FAR InitApplication(
HANDLE hInstance) /* current instance */
{
WNDCLASS wc;
/* Fill in window class structure with parameters that describe the */
/* main window. */
wc.style = NULL; /* Class style(s). */
wc.lpfnWndProc = MainWndProc; /* Function to retrieve messages for */
/* windows of this class. */
wc.cbClsExtra = 0; /* No per-class extra data. */
wc.cbWndExtra = 0; /* No per-window extra data. */
wc.hInstance = hInstance; /* Application that owns the class. */
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL; /* Name of menu resource in .RC file. */
wc.lpszClassName = "IPXWClass"; /* Name used in call to CreateWindow. */
hHourGlass = LoadCursor(NULL, IDC_WAIT);
/* Register the window class and return success/failure code. */
return (RegisterClass(&wc));
}
/****************************************************************************
FUNCTION: InitInstance(HANDLE, int)
PURPOSE: Saves instance handle and creates main window
****************************************************************************/
BOOL InitInstance(
HANDLE hInstance, /* Current instance identifier. */
int nCmdShow) /* Param for first ShowWindow() call. */
{
short xStart, yStart, xClient, yClient ;
/* Save the instance handle in static variable, which will be used in */
/* many subsequence calls from this application to Windows. */
hInst = hInstance;
SizeTheWindow (&xStart, &yStart, &xClient, &yClient) ;
/* Create a main window for this application instance. */
myWinHandle = CreateWindowEx(
WS_EX_TOPMOST, /* extended flag to make this window the topmost window */
"IPXWClass", /* See RegisterClass() call. */
"Phone Stats", /* Text for window title bar. */
WS_POPUP | WS_DLGFRAME | WS_SYSMENU, /* Window style. */
xStart, /* Default horizontal position. */
yStart, /* Default vertical position. */
xClient, /* Default width. */
yClient, /* Default height. */
NULL, /* Overlapped windows have no parent. */
NULL, /* Use the window class menu. */
hInstance, /* This instance owns this window. */
NULL /* Pointer not needed. */
);
/* If window could not be created, return "failure" */
if (!myWinHandle)
return (FALSE);
/* Make the window visible; update its client area; and return "success" */
ShowWindow(myWinHandle, SW_SHOWNOACTIVATE); /* Show the window */
UpdateWindow(myWinHandle); /* Sends WM_PAINT message */
return (TRUE); /* Returns the value from PostQuitMessage */
}
/****************************************************************************
FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
PURPOSE: Processes messages
MESSAGES:
WM_COMMAND - application menu (About dialog box)
WM_DESTROY - destroy window
****************************************************************************/
long FAR PASCAL MainWndProc(
HWND hWnd, /* window handle */
unsigned message, /* type of message */
WORD wParam, /* additional information */
LONG lParam) /* additional information */
{
PAINTSTRUCT ps;
HDC hDC;
static char str[100];
WORD cCode;
switch (message) {
case WM_LISTENESR:
ProcessPacket((ECB FAR *)lParam, hWnd);
break;
case WM_CREATE:
if(Init())
PostMessage(hWnd, WM_DESTROY, 0, 0);
__asm mov MySegment, ds;
cCode = GlobalPageLock (MySegment);
if (cCode == 0)
{ /* GlobalPageLock failed */
MessageBox (hWnd, "GlobalPageLock failed", "Error", MB_OK);
PostMessage(hWnd, WM_DESTROY, 0, 0);
}
cCode = GlobalPageLock((HGLOBAL) SELECTOROF(_ReceiveESRHandler));
if (cCode == 0)
{ /* GlobalPageLock failed */
MessageBox (hWnd, "GlobalPageLock failed", "Error", MB_OK);
PostMessage(hWnd, WM_DESTROY, 0, 0);
}
ListenForPacket();
return 0;
case WM_LBUTTONDOWN:
PostMessage(hWnd, WM_SYSCOMMAND, SC_MOVE+2, 0);
return 0;
case WM_PAINT :
hDC = BeginPaint (hWnd, &ps) ;
WndPaint (hWnd, hDC) ;
EndPaint (hWnd, &ps) ;
return 0 ;
case WM_DESTROY: /* message: window being destroyed */
Terminate();
PostQuitMessage(0);
break;
default: /* Passes it on if unproccessed */
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return (NULL);
}
BOOL FAR PASCAL ListenForPacket(void)
{
int i;
for (i=0; i<MAX_LISTEN_ECBS; i++)
{
/* prepare ipx header and allocate ecb structure */
_fmemset( (char *)&IPXReceive[i], '\0', sizeof(IPXHeader));
_fmemset( (char *)&listenECB[i], '\0', sizeof(ECB));
/* set up ecb for listen */
listenECB[i].ESRAddress = (void far *)_ReceiveESRHandler;
listenECB[i].socketNumber = socket;
listenECB[i].fragmentCount = 2;
listenECB[i].fragmentDescriptor[0].address = (char far *)&(IPXReceive[i]);
listenECB[i].fragmentDescriptor[0].size = sizeof(IPXHeader);
listenECB[i].fragmentDescriptor[1].address = (char far *)&displayData[i];
listenECB[i].fragmentDescriptor[1].size = sizeof(DISPLAYDATA);
/* listen for packet */
IPXListenForPacket(IPXTaskID,&listenECB[i]);
}
return (TRUE);
}
BOOL FAR PASCAL Init()
{
int ccode;
WORD psize;
IPXAddress internetworkAddr;
DWORD IPXTaskID = 0L;
psize = IPXGetMaxPacketSize();
ccode = IPXInitialize(&IPXTaskID, (WORD)MAX_LISTEN_ECBS, (WORD)psize);
if(ccode)
{
wsprintf(displayMessage, "IPXInitialize: %02X", ccode);
MessageBox(GetFocus(),displayMessage, "IPXInitialize", MB_ICONASTERISK | MB_OK);
return 1;
}
ccode = IPXOpenSocket(IPXTaskID, &socket, 0xFF);
if(ccode && ccode !=0xFF)
{
wsprintf(displayMessage, "Open socket returned: %x", ccode);
MessageBox(GetFocus(),displayMessage, "Open Socket", MB_ICONASTERISK | MB_OK);
return 1;
}
IPXGetInternetworkAddress(IPXTaskID, (BYTE far *)&internetworkAddr);
wsprintf(displayMessage, " Address: %02X%02X%02X%02X:%02X%02X%02X%02X%02X%02X:%04X",
internetworkAddr.network[0],
internetworkAddr.network[1],
internetworkAddr.network[2],
internetworkAddr.network[3],
internetworkAddr.node[0],
internetworkAddr.node[1],
internetworkAddr.node[2],
internetworkAddr.node[3],
internetworkAddr.node[4],
internetworkAddr.node[5],
NWWordSwap(socket));
// wsprintf(displayMessage, "Please send to the following address: %04X", NWWordSwap(socket));
MessageBox(GetFocus(),displayMessage, "Socket", MB_ICONASTERISK | MB_OK);
return 0;
}
BOOL FAR PASCAL Terminate()
{
int ccode, i;
for (i=1; i<=MAX_LISTEN_ECBS; i++)
ccode = IPXCancelEvent(IPXTaskID,&listenECB[i]);
IPXCloseSocket(IPXTaskID,socket);
ccode = IPXSPXDeinit(IPXTaskID);
GlobalPageUnlock(MySegment);
GlobalPageUnlock((HGLOBAL) SELECTOROF(_ReceiveESRHandler));
return TRUE;
}
void far pascal ReceiveESR(ECB far *ecb)
{
PostMessage(myWinHandle, WM_LISTENESR, 0, (DWORD)ecb);
return;
}
BOOL ProcessPacket(ECB FAR *ecb, HWND hwnd)
{
DISPLAYDATA far *data;
data = (DISPLAYDATA far *)ecb->fragmentDescriptor[1].address;
data->displayLineTwo[30] = '\0';
data->displayLineOne[30] = '\0';
wsprintf(processMessage, "%s\r\n%s ", data->displayLineOne , data->displayLineTwo );
IPXListenForPacket(IPXTaskID, ecb);
InvalidateRect (hwnd, NULL, TRUE) ;
return (TRUE);
}
void WndPaint (HWND hwnd, HDC hdc)
{
RECT rect ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, processMessage, -1, &rect, DT_CENTER | DT_NOCLIP) ;
}
void SizeTheWindow (short *pxStart, short *pyStart,
short *pxClient, short *pyClient)
{
HDC hdc ;
TEXTMETRIC tm ;
hdc = CreateIC ("DISPLAY", NULL, NULL, NULL) ;
GetTextMetrics (hdc, &tm) ;
DeleteDC (hdc) ;
*pxClient = 2 * GetSystemMetrics (SM_CXDLGFRAME) + 30*tm.tmAveCharWidth ;
*pxStart = GetSystemMetrics (SM_CXSCREEN) - *pxClient ;
*pyClient = 2 * GetSystemMetrics (SM_CYDLGFRAME) + 2*tm.tmHeight ;
*pyStart = GetSystemMetrics (SM_CYSCREEN) - *pyClient ;
}