--- mstools/samples/rpc/mandel/remote.c 2018/08/09 18:20:01 1.1 +++ mstools/samples/rpc/mandel/remote.c 2018/08/09 18:20:55 1.1.1.2 @@ -4,11 +4,11 @@ * Code to do the remote calculations for the Windows Mandelbrot Set * distributed drawing program. * - * Copyright (C) 1990 Microsoft Corporation. + * Copyright (C) 1990, 1992 Microsoft Corporation. * * Information coming into this module (via API calls) is based on * upper-left being (0,0) (the Windows standard). We translate that - * to PM standard (lower-left is (0,0) ) before we ship it out onto + * to lower-left is (0,0) before we ship it out onto * the net, and we do reverse translations accordingly. * * The iteration data is passed back to the main window procedure @@ -40,10 +40,10 @@ #include #include "mdlrpc.h" #endif - #include "mandel.h" + /* - * Tuning paramters + * Tuning parameters */ #define SVR_TABLE_SZ 20 #define MAX_PIPENAME_SZ CCHMAXPATH @@ -108,6 +108,16 @@ DWORD CalcThreshold( double ); BOOL InitRemote( HWND hWnd ) { +#ifdef RPC + RPC_STATUS status; // returned by RPC API function + unsigned char * pszUuid = "12345678-1234-1234-1234-123456789ABC"; + unsigned char * pszProtocolSequence = "ncacn_np"; + unsigned char * pszNetworkAddress = NULL; + unsigned char * pszEndpoint = "\\pipe\\mandel"; + unsigned char * pszOptions = NULL; + unsigned char * pszStringBinding; // long string +#endif + #ifndef RPC UNREFERENCED_PARAMETER(hWnd); #endif @@ -117,28 +127,38 @@ InitRemote( HWND hWnd ) strcpy(SvrTable[0].name, szLocal); SvrTable[0].iStatus = SS_LOCAL; - // set up remote entries #ifdef RPC - mdlrpc_ProtocolStack.TransportType = RPC_TRANSPORT_NAMEPIPE; - mdlrpc_ProtocolStack.TransportInfo = "\\device\\namedpipe\\mdlrpc"; - mdlrpc_ProtocolStack.TransportInfoLength = \ - strlen(mdlrpc_ProtocolStack.TransportInfo) + 1; - // add 1 for terminating null - - /* Call the Microsoft RPC V1.0 Alpha API function that lets */ - /* the client establish a connection with the server. */ - /* NOTE: This API function will be replaced in future */ - /* releases by the standard DCE RPC function. */ - status = RpcBindToInterface(&mdlrpc_ProtocolStack, - 0L, - &hMandel); +/* Select named pipes as the transport type and provide the */ +/* path to the server and named pipe that is used for RPC. */ + +/* Call the Microsoft RPC V1.0 Beta API function that lets */ +/* the client establish a connection with the server. */ + + status = RpcStringBindingCompose(pszUuid, + pszProtocolSequence, + pszNetworkAddress, + pszEndpoint, + pszOptions, + &pszStringBinding); + sprintf(pszFail, "RpcStringBindingCompose returned 0x%x for %s\n", + status, pszStringBinding); + MessageBox(hWnd, pszFail, "Mandelbrot RPC Application", + MB_ICONINFORMATION | MB_SYSTEMMODAL); if (status) { - sprintf(pszFail, "RpcBindToInterface returned 0x%x\n", status); - strcat(pszFail, "Please verify that the server side of the Mandel distributed application is running.\n"); - MessageBox(hWnd, pszFail, "Mandelbrot RPC Server Not Started", - MB_ICONHAND | MB_SYSTEMMODAL); - PostMessage(hWnd, WM_DESTROY, 0, 0L); - return FALSE; + PostMessage(hWnd, WM_DESTROY, 0, 0L); + return FALSE; + } + + status = RpcBindingFromStringBinding(pszStringBinding, + &hMandel); + + sprintf(pszFail, "RpcBindingFromStringBinding returned 0x%x for %s\n",\ + status, pszStringBinding); + MessageBox(hWnd, pszFail, "Mandelbrot RPC Application", + MB_ICONINFORMATION | MB_SYSTEMMODAL); + if (status) { + PostMessage(hWnd, WM_DESTROY, 0, 0L); + return FALSE; } #endif @@ -361,7 +381,7 @@ TakeDrawBuffer( void ) if (hSharedBuf == NULL) { - hSharedBuf = LocalAlloc(LMEM_MOVEABLE, MAX_BUFSIZE); + hSharedBuf = GlobalAlloc(GMEM_MOVEABLE, MAX_BUFSIZE); if (hSharedBuf == NULL) return FALSE; } @@ -378,7 +398,7 @@ GetDrawBuffer( void ) if (hSharedBuf == NULL) return NULL; - return (PDWORD) LocalLock(hSharedBuf); + return (PDWORD) GlobalLock(hSharedBuf); } @@ -386,7 +406,7 @@ GetDrawBuffer( void ) void FreeDrawBuffer( void ) { - LocalUnlock(hSharedBuf); + GlobalUnlock(hSharedBuf); } @@ -414,10 +434,10 @@ ReturnDrawBuffer( void ) DWORD CalcThreshold(double precision) { DWORD thres = 25; - double multiplier = (double) 100; + double multiplier = (double) 100.0; /* for every 100, multiply by 2 */ - while ( (precision *= multiplier) < (double)1) + while ( (precision *= multiplier) < (double)1.0) thres *= 2; return thres;