I have almost completed this very hard task on VS 2005 C++. There is is only part of prog, that I need to fix
Client:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream>
#include <ctype.h>
#include <windows.h>
#include "hello.h"
using namespace std;
#pragma comment(lib,"rpcndr.lib")
#pragma comment(lib,"rpcns4.lib")
#pragma comment(lib,"rpcrt4.lib")
void main()
{
char buffer[8] = "";
int N;
int k = 0;
while(k==0)
{
printf("Enter size of matrix (from 2 to 20): N=");
scanf ("%d", &N);
sprintf(buffer, "%d", N);
if ((N<2) || (N>20)) k=0;
else k=1;
}
unsigned short matrix [20][20];
cout << "Fill the matrix:\n";
for (size_t i = 0; i < N; ++i)
{
for (size_t j = 0; j < N; ++j)
{
cin >> matrix[i][j];
}
}
cout << "\nCurrent matrix... \n";
for (size_t i = 0; i < N; ++i)
{
for (size_t j = 0; j < N; ++j)
{
cout << matrix[i][j] << " ";
}
cout << endl << endl;
}
RPC_STATUS status;
const char* pszUuid = "906B0CE0-C70B-1067-B317-00DD010662DC";
const char* pszProtocolSequence = "ncacn_np";
const char* pszNetworkAddress = "127.0.0.1";
const char* pszEndpoint = "\\pipe\\he";
const char* pszOptions = NULL;
const char* pszStringBinding = NULL;
long ulCode=0;
status = RpcStringBindingCompose((RPC_CSTR)pszUuid,(RPC_CSTR) pszProtocolSequence, (RPC_CSTR)pszNetworkAddress, (RPC_CSTR)pszEndpoint, (RPC_CSTR)pszOptions, (RPC_CSTR*)&pszStringBinding);
if (status) exit(status);
status = RpcBindingFromStringBinding((RPC_CSTR)pszStringBinding, &hello_IfHandle);
if (status) exit(status);
RpcTryExcept
{
HelloProc((unsigned char *)buffer, (unsigned char **) matrix);
Shutdown();
}
RpcExcept(1)
{
ulCode = RpcExceptionCode();
printf("Runtime reported exception 0x%lx = %ld\n", ulCode, ulCode);
}
RpcEndExcept
status = RpcStringFree ((RPC_CSTR*)&pszStringBinding);
if (status) exit (status);
status = RpcBindingFree(&hello_IfHandle);
if (status) exit(status);
system("pause");
}
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);
}
Server:
Code:
// lab7_server.cpp : Defines the entry point for the console application.
//
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <iostream>
#include "hello.h"
using namespace std;
#pragma comment(lib,"RpcNdr.lib")
#pragma comment(lib,"Rpcns4.lib")
#pragma comment(lib,"RpcRT4.lib")
void main()
{
char buffer[8];
char matrix[20][20];
RPC_STATUS status;
const char* pszProtocolSequence = "ncacn_np";
const char* pszSecurity = NULL;
const char* pszEndpoint = "\\pipe\\he";
const int cMinCalls = 1;
const int cMaxCalls = 20;
const int fDontWait = FALSE;
status = RpcServerUseProtseqEp((RPC_CSTR)pszProtocolSequence, cMaxCalls, (RPC_CSTR)pszEndpoint, (RPC_CSTR)pszSecurity);
if (status) exit(status);
status = RpcServerRegisterIf(hello_v1_0_s_ifspec, NULL, NULL);
if (status) exit(status);
status = RpcServerListen(cMinCalls, cMaxCalls, fDontWait);
if (status) exit(status);
}
void HelloProc(unsigned char * buffer, unsigned char ** matrix)
{
int N;
N=atoi((char*)buffer);
cout << "Size of matrix from client= " << N << endl;
int **matrix_transfered = new int*[N];
for (size_t i = 0; i < N; ++i)
{
matrix_transfered[i] = new int[N];
}
for (size_t i = 0; i < N; ++i)
{
for (size_t j = 0; j < N; ++j)
{
matrix_transfered[i][j]=atoi((const char *) matrix[i][j]);
}
}
cout << "\nMatrix from client... \n";
for (size_t i = 0; i < N; ++i)
{
for (size_t j = 0; j < N; ++j)
{
cout << matrix_transfered[i][j] << " ";
}
cout << endl << endl;
}
system("PAUSE");
}
void Shutdown(void)
{
RPC_STATUS status;
printf("Вызываем RpcMgmtStopServerListening\n");
status = RpcMgmtStopServerListening(NULL);
printf("RpcMgmtStopServerListening returned: 0x%x\n", status);
if (status)
{
exit(status);
}
printf("Вызываем RpcServerUnregisterIf\n");
status = RpcServerUnregisterIf(NULL, NULL, FALSE);
printf("RpcServerUnregisterIf возвратила 0x%x\n", status);
if (status)
{
exit(status);
}
}
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);
}
Hello.h:
Code:
/* this ALWAYS GENERATED file contains the definitions for the interfaces */
/* File created by MIDL compiler version 6.00.0366 */
/* at Sat May 28 09:27:22 2011
*/
/* Compiler settings for hello.idl:
Oicf, W1, Zp8, env=Win32 (32b run)
protocol : dce , ms_ext, c_ext, robust
error checks: allocation ref bounds_check enum stub_data
VC __declspec() decoration level:
__declspec(uuid()), __declspec(selectany), __declspec(novtable)
DECLSPEC_UUID(), MIDL_INTERFACE()
*/
//@@MIDL_FILE_HEADING( )
#pragma warning( disable: 4049 ) /* more than 64k source lines */
/* verify that the <rpcndr.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCNDR_H_VERSION__
#define __REQUIRED_RPCNDR_H_VERSION__ 475
#endif
#include "rpc.h"
#include "rpcndr.h"
#ifndef __RPCNDR_H_VERSION__
#error this stub requires an updated version of <rpcndr.h>
#endif // __RPCNDR_H_VERSION__
#ifndef __hello_h__
#define __hello_h__
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
/* Forward Declarations */
#ifdef __cplusplus
extern "C"{
#endif
void * __RPC_USER MIDL_user_allocate(size_t);
void __RPC_USER MIDL_user_free( void * );
#ifndef __hello_INTERFACE_DEFINED__
#define __hello_INTERFACE_DEFINED__
/* interface hello */
/* [implicit_handle][unique][version][uuid] */
void HelloProc(
/* [string][in] */ unsigned char *buffer,
/* [string][in] */ unsigned char **matrix);
void Shutdown( void);
extern handle_t hello_IfHandle;
extern RPC_IF_HANDLE hello_v1_0_c_ifspec;
extern RPC_IF_HANDLE hello_v1_0_s_ifspec;
#endif /* __hello_INTERFACE_DEFINED__ */
/* Additional Prototypes for ALL interfaces */
/* end of Additional Prototypes */
#ifdef __cplusplus
}
#endif
#endif
Errors:
error LNK2001: unresolved external symbol _HelloProc
fatal error LNK1120: 1 unresolved externals