Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
CXHNDLC.C
Package: MSDN_VC98.zip [view]
Upload User: bangxh
Upload Date: 2007-01-31
Package Size: 42235k
Code Size: 5k
Category:
Windows Develop
Development Platform:
Visual C++
- /****************************************************************************
- Microsoft RPC Version 2.0
- Copyright Microsoft Corp. 1992, 1993, 1994- 1996
- cxhndl Example
- FILE: cxhndlc.c
- USAGE: cxhndlc -n network_address
- -p protocol_sequence
- -e endpoint
- -o options
- -f filename
- PURPOSE: Client side of RPC distributed application
- FUNCTIONS: main() - binds to server and calls remote procedure
- COMMENTS: This distributed application uses a context handle.
- ****************************************************************************/
- #include <stdlib.h>
- #include <stdio.h>
- #include "cxhndl.h" // header file generated by MIDL compiler
- #define PURPOSE
- "This Microsoft RPC Version 2.0 sample program demonstratesn
- the use of the [context_handle] attribute. For more informationn
- about attributes and RPC API functions, see the RPC programmingn
- guide and reference.nn"
- void Usage(char * pszProgramName)
- {
- fprintf(stderr, "%s", PURPOSE);
- fprintf(stderr, "Usage: %sn", pszProgramName);
- fprintf(stderr, " -p protocol_sequencen");
- fprintf(stderr, " -n network_addressn");
- fprintf(stderr, " -e endpointn");
- fprintf(stderr, " -o optionsn");
- fprintf(stderr, " -f filenamen");
- exit(1);
- }
- void _CRTAPI1 main(int argc, char **argv)
- {
- RPC_STATUS status;
- PCONTEXT_HANDLE_TYPE phContext = NULL;
- unsigned char * pbBuf = NULL;
- short cbRead; // count of bytes read
- unsigned char * pszUuid = NULL;
- unsigned char * pszProtocolSequence = "ncacn_np";
- unsigned char * pszNetworkAddress = NULL;
- unsigned char * pszEndpoint = "\pipe\cxhndl";
- unsigned char * pszOptions = NULL;
- unsigned char * pszStringBinding = NULL;
- unsigned char * pszFileName = "readme.txt";
- 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 'n': // network address
- pszNetworkAddress = argv[++i];
- break;
- case 'e':
- pszEndpoint = argv[++i];
- break;
- case 'o':
- pszOptions = argv[++i];
- break;
- case 'f':
- pszFileName = argv[++i];
- break;
- case 'h':
- case '?':
- default:
- Usage(argv[0]);
- }
- }
- else
- Usage(argv[0]);
- }
- pbBuf = (unsigned char *)
- midl_user_allocate(BUFSIZE * sizeof(unsigned char));
- /* Use a convenience function to concatenate the elements of */
- /* the string binding into the proper sequence. */
- status = RpcStringBindingCompose(pszUuid,
- pszProtocolSequence,
- pszNetworkAddress,
- pszEndpoint,
- pszOptions,
- &pszStringBinding);
- printf("RpcStringBindingCompose returned 0x%xn", status);
- printf("pszStringBinding = %sn", pszStringBinding);
- if (status) {
- exit(status);
- }
- /* Set the binding handle that will be used to bind to the server. */
- status = RpcBindingFromStringBinding(pszStringBinding,
- &hStarter);
- printf("RpcBindingFromStringBinding returned 0x%xn", status);
- if (status) {
- exit(status);
- }
- printf("Calling the remote procedure RemoteOpenn");
- if (RemoteOpen(&phContext, pszFileName) < 0) {
- printf("Unable to open %sn", pszFileName);
- Shutdown();
- exit(2);
- }
- /* Now the context handle also manages the binding. */
- status = RpcBindingFree(&hStarter);
- printf("RpcBindingFree returned 0x%xn", status);
- if (status) {
- exit(status);
- }
- /* Free the string binding */
- status = RpcStringFree(&pszStringBinding);
- printf("RpcStringFree returned 0x%xn", status);
- if (status) {
- exit(status);
- }
- printf("Calling the remote procedure RemoteReadn");
- while (RemoteRead(phContext, pbBuf, &cbRead) > 0) {
- for (i = 0; i < cbRead; i++)
- putchar(*(pbBuf+i));
- }
- printf("Calling the remote procedure RemoteClosen");
- if (RemoteClose(&phContext) < 0 ) {
- printf("Close failed on %sn", pszFileName);
- exit(2);
- }
- exit(0);
- } // end main()
- /*********************************************************************/
- /* MIDL allocate and free */
- /*********************************************************************/
- void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
- {
- return(malloc(len));
- }
- void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
- {
- free(ptr);
- }
- /* end cxhndlc.c */