REPASS.C
资源名称:MSDN_VC98.zip [点击查看]
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:5k
源码类别:
Windows编程
开发平台:
Visual C++
- /****************************************************************************
- Microsoft RPC Version 2.0
- Copyright Microsoft Corp. 1992, 1993, 1994- 1996
- repas Example
- FILE: repass.c
- USAGE: repass -p protocol_sequence
- -e endpoint
- -m max calls
- -n min calls
- -f flag for RpcServerListen
- PURPOSE: Server side of RPC distributed application repas
- FUNCTIONS: main() - registers server as RPC server
- COMMENTS: This sample program generates a client and server can share
- an interface, but one side can use a different representation
- than the other.
- The client side in this example does all operations using
- character strings, and the server side does all operations
- using UNICODE strings. Two procedures are provided, one
- defined with ASCII strings, one with UNICODE strings.
- The wire format reflects these definitions, yet the client
- and server see pure ASCII and pure UNICODE respectively.
- The [represent_as] attribute (used in the client and server
- side acf files) requires the four user-supplied functions
- whose names start with the name of the transmitted type
- (in the client side's case: WCHAR_STRING)
- The [in, out] attributes applied to remote procedure
- parameters require the two user-supplied functions
- midl_user_allocate and midl_user_free.
- The other functions are utilities that are used to
- build or display the data structures.
- ****************************************************************************/
- #include <stdlib.h>
- #include <stdio.h>
- #include <ctype.h>
- #include "repass.h" // header file generated by MIDL compiler
- #define PURPOSE
- "This Microsoft RPC Version 2.0 sample program demonstratesn
- the use of the [transmit_as] attribute. For more informationn
- about the attributes and the RPC API functions, see then
- RPC programming guide and reference.nn"
- void Usage(char * pszProgramName)
- {
- fprintf(stderr, "%s", PURPOSE);
- fprintf(stderr, "Usage: %sn", pszProgramName);
- fprintf(stderr, " -p protocol_sequencen");
- fprintf(stderr, " -e endpointn");
- fprintf(stderr, " -m maxcallsn");
- fprintf(stderr, " -n mincallsn");
- fprintf(stderr, " -f flag_wait_opn");
- exit(1);
- }
- /* main: register the interface, start listening for clients */
- void _CRTAPI1 main(int argc, char * argv[])
- {
- RPC_STATUS status;
- unsigned char * pszProtocolSequence = "ncacn_np";
- unsigned char * pszSecurity = NULL;
- unsigned char * pszEndpoint = "\pipe\repas";
- unsigned int cMinCalls = 1;
- unsigned int cMaxCalls = 20;
- unsigned int fDontWait = FALSE;
- int i;
- /* allow the user to override settings with command line switches */
- for (i = 1; i < argc; i++) {
- if ((*argv[i] == '-') || (*argv[i] == '/')) {
- switch (tolower(*(argv[i]+1))) {
- case 'p': // protocol sequence
- pszProtocolSequence = argv[++i];
- break;
- case 'e':
- pszEndpoint = argv[++i];
- break;
- case 'm':
- cMaxCalls = (unsigned int) atoi(argv[++i]);
- break;
- case 'n':
- cMinCalls = (unsigned int) atoi(argv[++i]);
- break;
- case 'f':
- fDontWait = (unsigned int) atoi(argv[++i]);
- break;
- case 'h':
- case '?':
- default:
- Usage(argv[0]);
- }
- }
- else
- Usage(argv[0]);
- }
- status = RpcServerUseProtseqEp(pszProtocolSequence,
- cMaxCalls,
- pszEndpoint,
- pszSecurity); // Security descriptor
- printf("RpcServerUseProtseqEp returned 0x%xn", status);
- if (status) {
- exit(status);
- }
- status = RpcServerRegisterIf(repas_ServerIfHandle, // interface to register
- NULL, // MgrTypeUuid
- NULL); // MgrEpv; null means use default
- printf("RpcServerRegisterIf returned 0x%xn", status);
- if (status) {
- exit(status);
- }
- printf("Calling RpcServerListenn");
- status = RpcServerListen(cMinCalls,
- cMaxCalls,
- fDontWait);
- printf("RpcServerListen returned: 0x%xn", status);
- if (status) {
- exit(status);
- }
- if (fDontWait) {
- printf("Calling RpcMgmtWaitServerListenn");
- status = RpcMgmtWaitServerListen(); // wait operation
- printf("RpcMgmtWaitServerListen returned: 0x%xn", status);
- if (status) {
- exit(status);
- }
- }
- } // end main()
- /* end file repass.c */