rpctestc.c

来自「VC++高级编程技巧与示例」· C语言 代码 · 共 87 行

C
87
字号
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include "RPCTest.h" 
#include "conio.h"

void main(int argc,char ** argv)
{
    RPC_STATUS status;
    LPSTR pszUuid             = NULL;
    LPSTR pszProtocolSequence = "ncacn_np";
    LPSTR pszNetworkAddress   = NULL;
    LPSTR pszEndpoint    = "\\pipe\\RPCTest";
    LPSTR pszOptions          = NULL;
    LPSTR pszStringBinding    = NULL;
	double val=0,re=0;
    unsigned long ulCode;

	if(argc<2)
	{
		printf("You need to input more than 1 parameters!\n");
		printf("Usage: \n");
		printf("RPCTest [val]\n");
		return;
	}

	val=atof(argv[1]);

    status = RpcStringBindingCompose((unsigned char *)pszUuid,
                                     (unsigned char *)pszProtocolSequence,
                                     (unsigned char *)pszNetworkAddress,
                                     (unsigned char *)pszEndpoint,
                                     (unsigned char *)pszOptions,
                                     (unsigned char **)&pszStringBinding);
    if (status) 
	{
        exit(status);
    }
    status = RpcBindingFromStringBinding((unsigned char *)pszStringBinding,
                                         (void **)&RPCTest_IfHandle);
 
    if (status) 
	{
        exit(status);
    }
 
    RpcTryExcept 
	{
        re=Calculate(val);
		printf("The result is : re=%f\n",re);
		printf("Now press any key, then we'll shutdown the server and client!\n");
		getch();
        Getout();
    }
    RpcExcept(1) 
	{
        ulCode = RpcExceptionCode();
        printf("Runtime reported exception 0x%lx = %ld\n", ulCode, ulCode);
    }
    RpcEndExcept
    status = RpcStringFree((unsigned char **)&pszStringBinding); 
 
    if (status) 
	{
        exit(status);
    }
 
    status = RpcBindingFree(&RPCTest_IfHandle);
 
    if (status) 
	{
        exit(status);
    }
    exit(0);
}

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);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?