oks2.c

来自「分布式传输功能」· C语言 代码 · 共 117 行

C
117
字号
/*file:hellos2.c*/
#include<fstream.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include "hello.h"
#include "hellop.h"
#include <assert.h>


//ifstream filein("moneydata.in");

void main()
{
	RPC_STATUS status;
	unsigned char *pszProtocolSequence ="ncacn_np";
	unsigned char *pszSecurity =NULL;
	unsigned char *pszEndpoint ="\\pipe\\hello2";
	unsigned int cMinCalls =1;
	unsigned int cMaxCalls =20;
	unsigned int fDontWait =FALSE;

	//初始化数据
	char ch,str[20],name[20];
	//int i=0;
	float balance=0;
    
	freopen("moneydata2.in","r",stdin);
	//scanf("%s",str);
	//printf("%s",str);
    count=0;
	while(scanf("%s",str)!=EOF)
	{
		strcpy(account[count].account_number,str);
		scanf("%s",name);
		strcpy(account[count].account_name,name);
		scanf("%f",&balance);
		account[count].account_balance=balance;
		count++;
	}
    //	printf("%d",i);
    
	// 初始化临界区
	InitializeCriticalSection(&g_cs);
/*	for(i=0;i<1000;i++)//记事本里至多1000上帐户
	{
		if(filein.eof()) break;
		filein>>str;
		strcpy(account[i].account_number,str);
		filein>>str;
		strcpy(account[i].account_name,str);
		filein>>balance;
		account[i].account_balance=balance;
	}*/

		

//	unsigned int balance=16000;
    //定义帐户变量
//	 char account_number[10]="101";
//	unsigned char *account_name="Peter";


//	account[5]={"101","Peter",16000,"102","John",1200,"103","Henryr",11000,"104","Pool",1};
//	strcpy(account[0].account_number,"101");
//	strcpy(account[0].account_name,account_name);
//	account[0].account_balance=12000;


	status =RpcServerUseProtseqEp(pszProtocolSequence,
		                          cMaxCalls,
                                  pszEndpoint,
								  pszSecurity);
	if(status)
	{
		exit(status);
	}

	status=RpcServerRegisterIf(hello_ServerIfHandle,
		                        NULL,NULL);

	if(status)
	{
		exit(status);
	}

	printf("Server2 is Listening\n");
	status =RpcServerListen(cMinCalls, cMaxCalls,fDontWait);
    
	if(status)
	{
		exit(status);
	}
    

	if (fDontWait) {
        printf("Calling RpcMgmtWaitServerListen\n");
        status = RpcMgmtWaitServerListen();  //  wait operation
        printf("RpcMgmtWaitServerListen returned: 0x%x\n", status);
        if (status) {
            exit(status);
        }
    }
}//end main()


//void __RPC_FAR * __RPC_API midl_user_allocate(size_t len)
void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
{
	return(malloc(len));
}
//void __RPC_API midl_user_free(void __RPC_FAR  *ptr)
void __RPC_USER midl_user_free( void __RPC_FAR *ptr)
{
	free(ptr);
}

⌨️ 快捷键说明

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