|
|
1.1 root 1: /**************************************************************************** 1.1.1.3 ! root 2: Microsoft RPC Version 1.0 ! 3: Copyright Microsoft Corp. 1992 ! 4: whello Example ! 5: ! 6: FILE: whelloc.c ! 7: ! 8: PURPOSE: RPC sample Windows client ! 9: Based on Win 3.x SDK Generic template for Windows applications ! 10: ! 11: FUNCTIONS: WinMain() - call initialization function, ! 12: process message loop ! 13: InitApplication() - initializ window data and register window ! 14: InitInstance() - save instance handle and create main window ! 15: MainWndProc() - process messages ! 16: ! 17: About() - process messages for "About" dialog box ! 18: Server() - process messages for "Server" dialog box ! 19: Endpoint() - process messages for "Endpoint" dialog box ! 20: Send() - process messages for "Send" dialog box; ! 21: sends on OK ! 22: ! 23: midl_user_allocate() - memory allocation function needed by RPC ! 24: midl_user_free() - memory free function needed by RPC ! 25: ! 26: COMMENTS: Windows version of the "Hello, world" example. ! 27: ! 28: Windows can have several copies of your application ! 29: running at the same time. The variable hInst keeps ! 30: track of which instance the application is so that ! 31: processing will be to the correct window. 1.1 root 32: 33: ****************************************************************************/ 34: 35: #include <stdio.h> 1.1.1.3 ! root 36: #include <stdlib.h> ! 37: #include <windows.h> ! 38: #include <windowsx.h> // select between win16 or win32 1.1 root 39: #include <string.h> 1.1.1.3 ! root 40: #include "whello.h" // header file generated by MIDL compiler ! 41: #include "whelloc.h" // client-specific header file 1.1 root 42: 1.1.1.3 ! root 43: /* global data */ 1.1 root 44: 1.1.1.3 ! root 45: unsigned char pszProtocolSequence[MAXPROTSEQ]; ! 46: unsigned char pszNetworkAddress[UNCLEN+1]; ! 47: unsigned char pszEndpoint[PATHLEN+1]; ! 48: unsigned char * pszUuid = NULL; ! 49: unsigned char * pszOptions = NULL; ! 50: unsigned char * pszStringBinding = NULL; ! 51: unsigned char pszString[MSGLEN]; 1.1 root 52: 1.1.1.3 ! root 53: int fBound = FALSE; // flag indicates whether client bound to server 1.1 root 54: 1.1.1.3 ! root 55: HANDLE hInst; // current instance ! 56: HCURSOR hHourGlass; // during calls to RPC API functions 1.1 root 57: 58: 1.1.1.3 ! root 59: /**************************************************************************** ! 60: ! 61: FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int) ! 62: ! 63: PURPOSE: calls initialization function, processes message loop 1.1 root 64: 1.1.1.3 ! root 65: COMMENTS: Windows recognizes this function by name as the initial ! 66: entry point for the program. This function calls the ! 67: application initialization routine, if no other instance ! 68: of the program is running, and always calls the instance ! 69: initialization routine. It then executes a message ! 70: retrieval and dispatch loop that is the top-level control ! 71: structure for the remainder of execution. The loop is ! 72: terminated when a WM_QUIT message is received, at which ! 73: time this function exits the application instance by ! 74: returning the value passed by PostQuitMessage(). 1.1 root 75: 1.1.1.3 ! root 76: If this function must abort before entering the message ! 77: loop, it returns the conventional value NULL. 1.1 root 78: 79: ****************************************************************************/ 1.1.1.3 ! root 80: ! 81: int WINAPI WinMain(HINSTANCE hInstance, // current instance ! 82: HINSTANCE hPrevInstance, // previous instance ! 83: LPSTR lpCmdLine, // command line ! 84: int nCmdShow) // show-window type (open/icon) 1.1 root 85: { 1.1.1.3 ! root 86: MSG msg; ! 87: 1.1 root 88: UNREFERENCED_PARAMETER(lpCmdLine); 89: 1.1.1.3 ! root 90: if (!hPrevInstance) // Other instances of app running? ! 91: if (!InitApplication(hInstance)) // Initialize shared things ! 92: return(FALSE); // Exits if unable to initialize 1.1 root 93: 94: /* Perform initializations that apply to a specific instance */ 95: if (!InitInstance(hInstance, nCmdShow)) 1.1.1.3 ! root 96: return(FALSE); 1.1 root 97: 98: /* Acquire and dispatch messages until a WM_QUIT message is received. */ 1.1.1.3 ! root 99: while (GetMessage(&msg, // message structure ! 100: (HWND)NULL, // handle of window receiving the message ! 101: 0, // lowest message to examine ! 102: 0)) // highest message to examine ! 103: { ! 104: TranslateMessage(&msg); // Translates virtual key codes ! 105: DispatchMessage(&msg); // Dispatches message to window 1.1 root 106: } 107: 1.1.1.3 ! root 108: return(msg.wParam); // Returns the value from PostQuitMessage 1.1 root 109: } 110: 111: 112: /**************************************************************************** 113: 114: FUNCTION: InitApplication(HANDLE) 115: 1.1.1.3 ! root 116: PURPOSE: Initializes window data and registers window class 1.1 root 117: 1.1.1.3 ! root 118: COMMENTS: This function is called at initialization time only if ! 119: no other instances of the application are running. This ! 120: function performs initialization tasks that can be done ! 121: once for any number of running instances. 1.1 root 122: 1.1.1.3 ! root 123: In this case, we initialize a window class by filling out ! 124: a data structure of type WNDCLASS and calling the Windows ! 125: RegisterClass() function. Since all instances of this ! 126: application use the same window class, we only need to do ! 127: this when the first instance is initialized. 1.1 root 128: 129: ****************************************************************************/ 130: 1.1.1.3 ! root 131: BOOL InitApplication(HANDLE hInstance) // current instance 1.1 root 132: { 133: WNDCLASS wc; 134: 1.1.1.3 ! root 135: /* Fill in window class structure with parameters that */ ! 136: /* describe the main window. */ ! 137: wc.style = 0; ! 138: wc.lpfnWndProc = (WNDPROC)MainWndProc; ! 139: wc.cbClsExtra = 0; ! 140: wc.cbWndExtra = 0; ! 141: wc.hInstance = hInstance; ! 142: wc.hIcon = LoadIcon(hInstance, "HelloIcon"); ! 143: wc.hCursor = LoadCursor(0, IDC_ARROW); 1.1 root 144: wc.hbrBackground = GetStockObject(WHITE_BRUSH); 1.1.1.3 ! root 145: wc.lpszMenuName = "GenericMenu"; ! 146: wc.lpszClassName = "GenericWClass"; 1.1 root 147: 148: /* Register the window class and return success/failure code. */ 1.1.1.3 ! root 149: return(RegisterClass(&wc)); 1.1 root 150: } 151: 152: 153: /**************************************************************************** 154: 1.1.1.3 ! root 155: FUNCTION: InitInstance(HANDLE, int) 1.1 root 156: 157: PURPOSE: Saves instance handle and creates main window 158: 1.1.1.3 ! root 159: COMMENTS: This function is called at initialization time for every ! 160: instance of this application. This function performs ! 161: initialization tasks that cannot be shared by multiple ! 162: instances. 1.1 root 163: 1.1.1.3 ! root 164: In this case, we save the instance handle in a static ! 165: variable and create and display the main program window. 1.1 root 166: 167: ****************************************************************************/ 168: 1.1.1.3 ! root 169: BOOL InitInstance(HANDLE hInstance, // Current instance identifier. ! 170: int nCmdShow) // Param for first ShowWindow() call. 1.1 root 171: { 1.1.1.3 ! root 172: HWND hWnd; // Main window handle. 1.1 root 173: 174: /* Save the instance handle in static variable, which will be used in */ 175: /* many subsequence calls from this application to Windows. */ 176: hInst = hInstance; 1.1.1.3 ! root 177: hHourGlass = LoadCursor(0, IDC_WAIT); ! 178: 1.1 root 179: /* Create a main window for this application instance. */ 1.1.1.3 ! root 180: hWnd = CreateWindow("GenericWClass", // See RegisterClass() call. ! 181: "RPC Sample Application", // Text for window title bar. ! 182: WS_OVERLAPPEDWINDOW, // Window style. ! 183: CW_USEDEFAULT, // Default horizontal position. ! 184: CW_USEDEFAULT, // Default vertical position. ! 185: CW_USEDEFAULT, // Default width. ! 186: CW_USEDEFAULT, // Default height. ! 187: (HWND) NULL, // Overlapped windows have no parent. ! 188: (HMENU) NULL, // Use the window class menu. ! 189: hInstance, // This instance owns this window. ! 190: (LPVOID) NULL // Pointer not needed. ! 191: ); 1.1 root 192: 193: /* If window could not be created, return "failure" */ 194: if (!hWnd) 1.1.1.3 ! root 195: return(FALSE); 1.1 root 196: 1.1.1.3 ! root 197: /* Initialize RPC binding data */ ! 198: strcpy(pszProtocolSequence, DEFAULT_PROT_SEQ); ! 199: strcpy(pszEndpoint, DEFAULT_ENDPOINT); ! 200: pszNetworkAddress[0] = '\0'; ! 201: strcpy(pszString, DEFAULT_MESSAGE); 1.1 root 202: 203: /* Make the window visible; update its client area; and return "success" */ 1.1.1.3 ! root 204: ShowWindow(hWnd, nCmdShow); // Show the window ! 205: UpdateWindow(hWnd); // Send WM_PAINT message 1.1 root 206: 1.1.1.3 ! root 207: return(TRUE); // Return the value from PostQuitMessage 1.1 root 208: } 209: 1.1.1.3 ! root 210: 1.1 root 211: /**************************************************************************** 212: 213: FUNCTION: MainWndProc(HWND, UINT, WPARAM, LPARAM) 214: 215: PURPOSE: Processes messages 1.1.1.3 ! root 216: ! 217: MESSAGES: WM_COMMAND - application menu (About dialog box) ! 218: WM_DESTROY - destroy window 1.1 root 219: 1.1.1.3 ! root 220: COMMENTS: To process the IDM_ABOUT message, call MakeProcInstance() ! 221: to get the current instance address of the About() function. ! 222: Then call Dialog box which will create the box according to ! 223: the information in your generic.rc file and turn control ! 224: over to the About() function. When it returns, free the ! 225: intance address. 1.1 root 226: 227: ****************************************************************************/ 228: 1.1.1.3 ! root 229: long APIENTRY MainWndProc(HWND hWnd, // window handle ! 230: UINT message, // type of message ! 231: WPARAM wParam, // additional information ! 232: LPARAM lParam) // additional information 1.1 root 233: { 1.1.1.3 ! root 234: DLGPROC lpProc; // pointer to the dialog box function 1.1 root 235: 236: switch (message) { 237: 1.1.1.3 ! root 238: case WM_CREATE: ! 239: ! 240: #ifdef WIN16 ! 241: PostMessage(hWnd, WM_COMMAND, IDM_SERVER, 0L); // force server spec ! 242: #else ! 243: PostMessage(hWnd, WM_COMMAND, IDM_BIND, 0L); // bind to server ! 244: #endif ! 245: break; ! 246: ! 247: case WM_COMMAND: // message: command from application menu ! 248: switch (wParam) { ! 249: ! 250: case IDM_BIND: ! 251: if (Bind(hWnd) != RPC_S_OK) ! 252: PostMessage(hWnd, WM_DESTROY, 0, 0L); ! 253: break; ! 254: ! 255: case IDM_ABOUT: ! 256: lpProc = MakeProcInstance(About, hInst); ! 257: DialogBox(hInst, // current instance ! 258: "AboutBox", // resource to use ! 259: hWnd, // parent handle ! 260: lpProc); // About() instance address ! 261: FreeProcInstance(lpProc); ! 262: break; ! 263: ! 264: case IDM_SERVER: ! 265: lpProc = MakeProcInstance(Server, hInst); ! 266: DialogBox(hInst, // current instance ! 267: "ServerBox", // resource to use ! 268: hWnd, // parent handle ! 269: lpProc); // Server instance address ! 270: FreeProcInstance(lpProc); ! 271: break; ! 272: ! 273: case IDM_ENDPOINT: ! 274: lpProc = MakeProcInstance(Endpoint, hInst); ! 275: DialogBox(hInst, // current instance ! 276: "EndpointBox",// resource to use ! 277: hWnd, // parent handle ! 278: lpProc); // Server instance address ! 279: FreeProcInstance(lpProc); ! 280: break; ! 281: ! 282: case IDM_SEND: ! 283: lpProc = MakeProcInstance(Send, hInst); ! 284: DialogBox(hInst, // current instance ! 285: "SendBox", // resource to use ! 286: hWnd, // parent handle ! 287: lpProc); // Server instance address ! 288: FreeProcInstance(lpProc); ! 289: break; ! 290: ! 291: case IDM_EXIT: ! 292: DestroyWindow(hWnd); ! 293: if (fBound == TRUE) { ! 294: RpcTryExcept { ! 295: Shutdown(); // shut down the server ! 296: } ! 297: RpcExcept(1) { ! 298: MessageBox(hWnd, ! 299: EXCEPT_MSG, ! 300: "Remote Procedure Call", ! 301: MB_ICONINFORMATION); ! 302: } ! 303: RpcEndExcept ! 304: } ! 305: break; ! 306: ! 307: default: // Let Windows process it ! 308: return(DefWindowProc(hWnd, message, wParam, lParam)); ! 309: ! 310: } ! 311: break; ! 312: ! 313: case WM_DESTROY: // message: window being destroyed ! 314: PostQuitMessage(0); ! 315: break; ! 316: ! 317: default: // Passes it on if unprocessed ! 318: return(DefWindowProc(hWnd, message, wParam, lParam)); ! 319: 1.1 root 320: } 1.1.1.3 ! root 321: ! 322: return(0); 1.1 root 323: } 324: 325: 326: /**************************************************************************** 327: 328: FUNCTION: Server(HWND, unsigned, WORD, LONG) 329: 330: PURPOSE: Processes messages for "Server" dialog box 331: 1.1.1.3 ! root 332: MESSAGES: WM_INITDIALOG - initialize dialog box ! 333: WM_COMMAND - Input received ! 334: ! 335: COMMENTS: No initialization is needed for this particular dialog box, ! 336: but TRUE must be returned to Windows. ! 337: ! 338: Wait for user to click on "Ok" button, then close the dialog box. ! 339: ! 340: ****************************************************************************/ ! 341: ! 342: BOOL APIENTRY Server(HWND hDlg, // window handle of the dialog box ! 343: UINT message, // type of message ! 344: UINT wParam, // message-specific information ! 345: LONG lParam) ! 346: { ! 347: HCURSOR hOld; ! 348: ! 349: UNREFERENCED_PARAMETER(lParam); ! 350: ! 351: switch (message) { ! 352: ! 353: case WM_INITDIALOG: // message: initialize dialog box ! 354: SetDlgItemText((HANDLE)hDlg, IDD_SERVERNAME, pszNetworkAddress); ! 355: return(TRUE); ! 356: ! 357: case WM_COMMAND: // message: received a command ! 358: switch(wParam) { ! 359: ! 360: case IDCANCEL: // System menu close command? ! 361: EndDialog(hDlg, FALSE); ! 362: return(TRUE); ! 363: ! 364: case IDOK: // "OK" box selected? ! 365: GetDlgItemText(hDlg, IDD_SERVERNAME, pszNetworkAddress, UNCLEN); ! 366: ! 367: /* pszNetworkAddress must start with two backslashes */ ! 368: if (pszNetworkAddress[0] != '\0' && ! 369: strncmp(pszNetworkAddress, "\\\\", 2)) { ! 370: ! 371: unsigned char oldNetAddr[UNCLEN+1]; 1.1 root 372: 1.1.1.3 ! root 373: strcpy(oldNetAddr, pszNetworkAddress); ! 374: sprintf(pszNetworkAddress, "\\\\%s", oldNetAddr); ! 375: } 1.1 root 376: 1.1.1.3 ! root 377: hOld = SetCursor(hHourGlass); ! 378: if (Bind(hDlg) != RPC_S_OK) { ! 379: EndDialog(hDlg, FALSE); ! 380: return(FALSE); ! 381: } 1.1 root 382: 1.1.1.3 ! root 383: SetCursor(hOld); ! 384: EndDialog(hDlg, TRUE); ! 385: return(TRUE); 1.1 root 386: 1.1.1.3 ! root 387: } ! 388: ! 389: } ! 390: ! 391: return(FALSE); // Didn't process a message 1.1 root 392: } 393: 1.1.1.3 ! root 394: 1.1 root 395: /**************************************************************************** 396: 397: FUNCTION: About(HWND, unsigned, WORD, LONG) 398: 399: PURPOSE: Processes messages for "About" dialog box 400: 1.1.1.3 ! root 401: MESSAGES: WM_INITDIALOG - initialize dialog box ! 402: WM_COMMAND - Input received 1.1 root 403: 1.1.1.3 ! root 404: COMMENTS: No initialization is needed for this particular dialog box, ! 405: but TRUE must be returned to Windows. 1.1 root 406: 1.1.1.3 ! root 407: Wait for user to click on "Ok" button, then close the dialog box. 1.1 root 408: 409: ****************************************************************************/ 1.1.1.3 ! root 410: ! 411: BOOL APIENTRY About(HWND hDlg, // window handle of the dialog box ! 412: UINT message, // type of message ! 413: UINT wParam, // message-specific information ! 414: LONG lParam) 1.1 root 415: { 416: UNREFERENCED_PARAMETER(lParam); 417: 418: switch (message) { 419: 1.1.1.3 ! root 420: case WM_INITDIALOG: // message: initialize dialog box ! 421: return(TRUE); ! 422: ! 423: case WM_COMMAND: // message: received a command ! 424: if (wParam == IDOK || wParam == IDCANCEL) { ! 425: EndDialog(hDlg, TRUE); ! 426: return(TRUE); ! 427: } ! 428: break; ! 429: 1.1 root 430: } 1.1.1.3 ! root 431: ! 432: return(FALSE); // Didn't process a message 1.1 root 433: } 1.1.1.3 ! root 434: ! 435: 1.1 root 436: /**************************************************************************** 437: 438: FUNCTION: Endpoint(HWND, unsigned, WORD, LONG) 439: 440: PURPOSE: Processes messages for "Endpoint" dialog box 441: 1.1.1.3 ! root 442: MESSAGES: WM_INITDIALOG - initialize dialog box ! 443: WM_COMMAND - Input received 1.1 root 444: 1.1.1.3 ! root 445: COMMENTS: No initialization is needed for this particular dialog box, ! 446: but TRUE must be returned to Windows. 1.1 root 447: 1.1.1.3 ! root 448: Wait for user to click on "Ok" button, then close the dialog box. 1.1 root 449: 450: ****************************************************************************/ 1.1.1.3 ! root 451: ! 452: BOOL APIENTRY Endpoint(HWND hDlg, // window handle of the dialog box ! 453: UINT message, // type of message ! 454: UINT wParam, // message-specific information ! 455: LONG lParam) 1.1 root 456: { 1.1.1.3 ! root 457: HCURSOR hOld; ! 458: 1.1 root 459: UNREFERENCED_PARAMETER(lParam); 460: 1.1.1.3 ! root 461: switch (message) { ! 462: ! 463: case WM_INITDIALOG: // message: initialize dialog box ! 464: SetDlgItemText(hDlg, IDD_ENDPOINTNAME, pszEndpoint); ! 465: return(TRUE); ! 466: ! 467: case WM_COMMAND: // message: received a command ! 468: switch(wParam) { ! 469: ! 470: case IDCANCEL: ! 471: EndDialog(hDlg, FALSE); ! 472: return(TRUE); 1.1 root 473: 1.1.1.3 ! root 474: case IDOK: ! 475: GetDlgItemText(hDlg, IDD_ENDPOINTNAME, pszEndpoint, PATHLEN); 1.1 root 476: 1.1.1.3 ! root 477: hOld = SetCursor(hHourGlass); ! 478: if (Bind(hDlg) != RPC_S_OK) { ! 479: EndDialog(hDlg, FALSE); ! 480: return(FALSE); ! 481: } ! 482: ! 483: SetCursor(hOld); ! 484: EndDialog(hDlg, TRUE); ! 485: return(TRUE); ! 486: ! 487: } ! 488: ! 489: } ! 490: ! 491: return(FALSE); // Didn't process a message 1.1 root 492: } 493: 1.1.1.3 ! root 494: 1.1 root 495: /**************************************************************************** 496: 497: FUNCTION: Send(HWND, unsigned, WORD, LONG) 498: 499: PURPOSE: Processes messages for "Send" dialog box 500: 1.1.1.3 ! root 501: MESSAGES: WM_INITDIALOG - initialize dialog box ! 502: WM_COMMAND - Input received 1.1 root 503: 1.1.1.3 ! root 504: COMMENTS: No initialization is needed for this particular dialog box, ! 505: but TRUE must be returned to Windows. 1.1 root 506: 1.1.1.3 ! root 507: Wait for user to click on "Ok" button, then close the dialog box. 1.1 root 508: 509: ****************************************************************************/ 510: 1.1.1.3 ! root 511: BOOL APIENTRY Send(HWND hDlg, // window handle of the dialog box ! 512: UINT message, // type of message ! 513: UINT wParam, // message-specific information ! 514: LONG lParam) 1.1 root 515: { 1.1.1.3 ! root 516: UNREFERENCED_PARAMETER(lParam); ! 517: ! 518: switch (message) { ! 519: ! 520: case WM_INITDIALOG: // message: initialize dialog box ! 521: SetDlgItemText(hDlg, IDD_MESSAGE, pszString); ! 522: return(TRUE); ! 523: ! 524: case WM_COMMAND: // message: received a command ! 525: switch(wParam) { 1.1 root 526: 1.1.1.3 ! root 527: case IDCANCEL: ! 528: EndDialog(hDlg, FALSE); ! 529: return(TRUE); 1.1 root 530: 1.1.1.3 ! root 531: case IDOK: ! 532: GetDlgItemText(hDlg, IDD_MESSAGE, pszString, MSGLEN); 1.1 root 533: 1.1.1.3 ! root 534: RpcTryExcept { ! 535: HelloProc(pszString); // make call with user message ! 536: } ! 537: RpcExcept(1) { ! 538: char pszFail[MSGLEN]; ! 539: ! 540: sprintf(pszFail, "%s (0x%x)\n", EXCEPT_MSG, RpcExceptionCode()); ! 541: MessageBox(hDlg, ! 542: pszFail, ! 543: "Remote Procedure Call", ! 544: MB_ICONINFORMATION); ! 545: } ! 546: RpcEndExcept ! 547: ! 548: EndDialog(hDlg, TRUE); ! 549: return(TRUE); ! 550: ! 551: } ! 552: ! 553: } ! 554: ! 555: return(FALSE); // Didn't process a message 1.1 root 556: } 557: 1.1.1.3 ! root 558: 1.1 root 559: /**************************************************************************** 560: 1.1.1.3 ! root 561: FUNCTION: midl_user_allocate(size_t) 1.1 root 562: 563: PURPOSE: Allocate memory as needed by the RPC runtime library 564: 1.1.1.3 ! root 565: COMMENTS: The stubs or runtime libraries may need to allocate memory. ! 566: By convention, they call a user-specified function named ! 567: midl_user_allocate. In this application, no memory ! 568: management is needed, so a dummy function is provided. 1.1 root 569: 570: ****************************************************************************/ 571: 1.1.1.3 ! root 572: void __RPC_FAR * __RPC_API midl_user_allocate(size_t len) 1.1 root 573: { 574: UNREFERENCED_PARAMETER(len); 575: return(NULL); // no memory management required 576: } 577: 1.1.1.3 ! root 578: 1.1 root 579: /**************************************************************************** 580: 1.1.1.3 ! root 581: FUNCTION: midl_user_free(void *) 1.1 root 582: 583: PURPOSE: Free memory as needed by the RPC runtime library 584: 1.1.1.3 ! root 585: COMMENTS: The stubs or runtime libraries may need to free memory. ! 586: By convention, they call a user-specified function named ! 587: midl_user_free. In this application, no memory allocation ! 588: is needed so a dummy function is provided. 1.1 root 589: 590: ****************************************************************************/ 591: 1.1.1.3 ! root 592: void __RPC_API midl_user_free(void __RPC_FAR * ptr) 1.1 root 593: { 594: UNREFERENCED_PARAMETER(ptr); 1.1.1.3 ! root 595: return; // no memory management required 1.1 root 596: } 597: 1.1.1.3 ! root 598: 1.1 root 599: /**************************************************************************** 600: 601: FUNCTION: Bind(HWND) 602: 603: PURPOSE: Make RPC API calls to bind to the server application 604: 1.1.1.3 ! root 605: COMMENTS: The binding calls are made from InitInstance() and ! 606: whenever the user changes the server name or endpoint. ! 607: If the bind operation is successful, the global flag ! 608: fBound is set to TRUE. 1.1 root 609: 1.1.1.3 ! root 610: The global flag fBound is used to determine whether to ! 611: call the RPC API function RpcBindingFree. 1.1 root 612: 613: ****************************************************************************/ 614: 615: RPC_STATUS Bind(HWND hWnd) 616: { 617: RPC_STATUS status; 1.1.1.3 ! root 618: char pszFail[MSGLEN]; 1.1 root 619: 1.1.1.3 ! root 620: if (fBound == TRUE) { // unbind only if bound ! 621: status = RpcStringFree(&pszStringBinding); ! 622: if (status) { ! 623: MessageBox(hWnd, "RpcStringFree failed", "RPC Error", MB_ICONSTOP); ! 624: return(status); ! 625: } ! 626: ! 627: status = RpcBindingFree(&hWHello); ! 628: if (status) { ! 629: MessageBox(hWnd, "RpcBindingFree failed", "RPC Error", MB_ICONSTOP); ! 630: return(status); ! 631: } ! 632: ! 633: fBound = FALSE; // unbind successful; reset flag 1.1 root 634: } 1.1.1.3 ! root 635: 1.1 root 636: status = RpcStringBindingCompose(pszUuid, 637: pszProtocolSequence, 1.1.1.3 ! root 638: pszNetworkAddress, ! 639: pszEndpoint, 1.1 root 640: pszOptions, 1.1.1.3 ! root 641: &pszStringBinding); 1.1 root 642: if (status) { 1.1.1.3 ! root 643: sprintf(pszFail, "RpcStringBindingCompose failed: (0x%x)\nNetwork Address = %s\n", ! 644: status, pszNetworkAddress); ! 645: MessageBox(hWnd, ! 646: pszFail, ! 647: "RPC Runtime Error", ! 648: MB_ICONEXCLAMATION); ! 649: return(status); 1.1 root 650: } 1.1.1.3 ! root 651: 1.1 root 652: status = RpcBindingFromStringBinding(pszStringBinding, 1.1.1.3 ! root 653: &hWHello); 1.1 root 654: if (status) { 1.1.1.3 ! root 655: sprintf(pszFail, "RpcBindingFromStringBinding failed: (0x%x)\nString = %s\n", ! 656: status, pszStringBinding); ! 657: MessageBox(hWnd, ! 658: pszFail, ! 659: "RPC Runtime Error", ! 660: MB_ICONEXCLAMATION); ! 661: return(status); ! 662: } ! 663: ! 664: fBound = TRUE; // bind successful; reset flag ! 665: ! 666: return(status); 1.1 root 667: } 668: 669: /**** end whelloc.c ****/
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.