Site hosted by Angelfire.com: Build your free website today!

sample1


Home Su

 

 

 

 

 

 

 

sample1 (RPC) 

This simple sample is .... 

D:\STUDI\RPC\sample1> uuidgen /i /osample1.idl

// file: sample1.idl

[
uuid(905d0ec3-76ad-4d7a-be5c-1358c003114e),
version(1.0)
]
interface INTERFACENAME
{

}


 
// file: sample1.idl
[
uuid(905d0ec3-76ad-4d7a-be5c-1358c003114e),
version(1.0)
]
interface sample1
{
   void PrintString( [in, string] unsigned char * pszString );
   void ShutdownRPCServer(void);
}
 
// file: sample1.acf
[implicit_handle ( handle_t sample1_ifHandle ) ] interface sample1
{
}

 

 


D:\STUDI\RPC\sample1> midl /nocpp sample1.idl
Microsoft (R) MIDL Compiler Version 5.01.0164
Copyright (c) Microsoft Corp 1991-1997. All rights reserved.
Processing .\sample1.idl
Processing .\sample1.acf

This will generate the file sample1.h, sample1_c.c and sample1_s.c

 

sample1.h
/* this ALWAYS GENERATED file contains the definitions for the interfaces */
/* File created by MIDL compiler version 5.01.0164 at Fri Feb 28 23:45:44 2003 */
/* Compiler settings for sample1.idl:
Os (OptLev
=s), W1, Zp8, env=Win32, ms_ext, c_ext
error checks
: allocation ref bounds_check enum stub_data
*/
//@@MIDL_FILE_HEADING( )


/* verify that the <rpcndr.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCNDR_H_VERSION__
#define __REQUIRED_RPCNDR_H_VERSION__ 440
#endif

#include "rpc.h"
#include "rpcndr.h"

#ifndef __sample1_h__
#define __sample1_h__

#ifdef __cplusplus
extern
"C"{
#endif

/* Forward Declarations */

void __RPC_FAR
* __RPC_USER MIDL_user_allocate(size_t);
void __RPC_USER MIDL_user_free( void __RPC_FAR
* );

#ifndef __sample1_INTERFACE_DEFINED__
#define __sample1_INTERFACE_DEFINED__

/* interface sample1 */
/* [implicit_handle][version][uuid] */

void PrintString(
/* [string][in] */ unsigned char __RPC_FAR *pszString);

void ShutdownRPCServer( void);

extern handle_t sample1_ifHandle;

extern RPC_IF_HANDLE sample1_v1_0_c_ifspec;
extern RPC_IF_HANDLE sample1_v1_0_s_ifspec;
#endif /* __sample1_INTERFACE_DEFINED__ */

/* Additional Prototypes for ALL interfaces */

/* end of Additional Prototypes */

#ifdef __cplusplus
}
#endif

#endif

sample1_c.c
/* this ALWAYS GENERATED file contains the RPC client stubs */
/* File created by MIDL compiler version 5.01.0164 */
/* at Fri Feb 28 23:45:44 2003 */
/* Compiler settings for sample1.idl:
Os (OptLev=s), W1, Zp8, env=Win32, ms_ext, c_ext
error checks: allocation ref bounds_check enum stub_data
*/

//@@MIDL_FILE_HEADING( )

#include <string.h>
#if defined( _ALPHA_ )
#include <stdarg.h>
#endif

#include "sample1.h"

#define TYPE_FORMAT_STRING_SIZE 7
#define PROC_FORMAT_STRING_SIZE 9

typedef struct _MIDL_TYPE_FORMAT_STRING
{
short Pad;
unsigned char Format[ TYPE_FORMAT_STRING_SIZE ];
} MIDL_TYPE_FORMAT_STRING;

typedef struct _MIDL_PROC_FORMAT_STRING
{
short Pad;
unsigned char Format[ PROC_FORMAT_STRING_SIZE ];
} MIDL_PROC_FORMAT_STRING;


extern const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;
extern const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;

/* Standard interface: sample1, ver. 1.0,
GUID={0x905d0ec3,0x76ad,0x4d7a,{0xbe,0x5c,0x13,0x58,0xc0,0x03,0x11,0x4e}} */


handle_t sample1_ifHandle;


static const RPC_CLIENT_INTERFACE sample1___RpcClientInterface =
{
sizeof(RPC_CLIENT_INTERFACE),
{{0x905d0ec3,0x76ad,0x4d7a,{0xbe,0x5c,0x13,0x58,0xc0,0x03,0x11,0x4e}},{1,0}},
{{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}},
0,0,0,0,0,0 };
RPC_IF_HANDLE sample1_v1_0_c_ifspec = (RPC_IF_HANDLE)& sample1___RpcClientInterface;

extern const MIDL_STUB_DESC sample1_StubDesc;
static RPC_BINDING_HANDLE sample1__MIDL_AutoBindHandle;

void PrintString(
/* [string][in] */ unsigned char __RPC_FAR *pszString)
{

RPC_BINDING_HANDLE _Handle = 0;

RPC_MESSAGE _RpcMessage;

MIDL_STUB_MESSAGE _StubMsg;

if(!pszString) { RpcRaiseException(RPC_X_NULL_REF_POINTER); }
RpcTryFinally  { NdrClientInitializeNew( ( PRPC_MESSAGE )&_RpcMessage,
                                         ( PMIDL_STUB_MESSAGE )&_StubMsg,
                                         ( PMIDL_STUB_DESC )&sample1_StubDesc,
                                          0);

_Handle = sample1_ifHandle;

_StubMsg.BufferLength = 12U;
NdrConformantStringBufferSize( (PMIDL_STUB_MESSAGE) &_StubMsg,
(unsigned char __RPC_FAR *)pszString,
(PFORMAT_STRING) &__MIDL_TypeFormatString.Format[4] );

NdrGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg, _StubMsg.BufferLength, _Handle );

NdrConformantStringMarshall( (PMIDL_STUB_MESSAGE)& _StubMsg,
(unsigned char __RPC_FAR *)pszString,
(PFORMAT_STRING) &__MIDL_TypeFormatString.Format[4] );

NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR *) _StubMsg.Buffer );

}
RpcFinally
{
NdrFreeBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg );

}
RpcEndFinally

}


void ShutdownRPCServer( void)
{

RPC_BINDING_HANDLE _Handle = 0;

RPC_MESSAGE _RpcMessage;

MIDL_STUB_MESSAGE _StubMsg;

RpcTryFinally
{
NdrClientInitializeNew(
( PRPC_MESSAGE )&_RpcMessage,
( PMIDL_STUB_MESSAGE )&_StubMsg,
( PMIDL_STUB_DESC )&sample1_StubDesc,
1);


_Handle = sample1_ifHandle;


_StubMsg.BufferLength = 0U;
NdrGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg, _StubMsg.BufferLength, _Handle );

NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR *) _StubMsg.Buffer );

}
RpcFinally
{
NdrFreeBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg );

}
RpcEndFinally

}


static const MIDL_STUB_DESC sample1_StubDesc =
{
(void __RPC_FAR *)& sample1___RpcClientInterface,
MIDL_user_allocate,
MIDL_user_free,
&sample1_ifHandle,
0,
0,
0,
0,
__MIDL_TypeFormatString.Format,
1,
/* -error bounds_check flag */
0x10001,
/* Ndr library version */
0,
0x50100a4,
/* MIDL Version 5.1.164 */
0,
0,
0,
/* notify & notify_flag routine table */
1,
/* Flags */
0,
/* Reserved3 */
0,
/* Reserved4 */
0
/* Reserved5 */
};

#if !defined(__RPC_WIN32__)
#error Invalid build platform for this stub.
#endif

static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =
{
0,
{

0x4d,
/* FC_IN_PARAM */
#ifndef _ALPHA_
0x1,
/* x86, MIPS & PPC Stack size = 1 */
#else
0x2,
/* Alpha Stack size = 2 */
#endif
/* 2 */ NdrFcShort( 0x2 ), /* Type Offset=2 */
/* 4 */ 0x5b, /* FC_END */
0x5c,
/* FC_PAD */
/* 6 */ 0x5b, /* FC_END */
0x5c,
/* FC_PAD */

0x0
}
};

static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =
{
0,
{
NdrFcShort( 0x0 ),
/* 0 */
/* 2 */
0x11, 0x8,
/* FC_RP [simple_pointer] */
/* 4 */
0x22,
/* FC_C_CSTRING */
0x5c,
/* FC_PAD */
0x0
}
};
sample1_s.c

 

 /* this ALWAYS GENERATED file contains the RPC server stubs */
/* File created by MIDL compiler version 5.01.0164 */
// Compiler settings for sample1.idl: Os (OptLev=s), W1, Zp8, env=Win32, ms_ext, c_ext error checks: allocation ref bounds_check enum stub_data
//@@MIDL_FILE_HEADING( )


#include <string.h>
#include "sample1.h"

#define TYPE_FORMAT_STRING_SIZE 7
#define PROC_FORMAT_STRING_SIZE 9

typedef struct _MIDL_TYPE_FORMAT_STRING
{
short Pad;
unsigned char Format[ TYPE_FORMAT_STRING_SIZE ];
} MIDL_TYPE_FORMAT_STRING;

typedef struct _MIDL_PROC_FORMAT_STRING
{
short Pad;
unsigned char Format[ PROC_FORMAT_STRING_SIZE ];
} MIDL_PROC_FORMAT_STRING;

extern const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;
extern const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;

/* Standard interface: sample1, ver. 1.0,
GUID={0x905d0ec3,0x76ad,0x4d7a,{0xbe,0x5c,0x13,0x58,0xc0,0x03,0x11,0x4e}} */



extern RPC_DISPATCH_TABLE sample1_v1_0_DispatchTable;

static const RPC_SERVER_INTERFACE sample1___RpcServerInterface =
{
sizeof(RPC_SERVER_INTERFACE),
{{0x905d0ec3,0x76ad,0x4d7a,{0xbe,0x5c,0x13,0x58,0xc0,0x03,0x11,0x4e}},{1,0}},
{{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}},
&sample1_v1_0_DispatchTable,
0,
0,
0,
0,
0
};
RPC_IF_HANDLE sample1_v1_0_s_ifspec = (RPC_IF_HANDLE)& sample1___RpcServerInterface;

extern const MIDL_STUB_DESC sample1_StubDesc;

void __RPC_STUB
sample1_PrintString(
PRPC_MESSAGE _pRpcMessage )
{
int _RetVal;
MIDL_STUB_MESSAGE _StubMsg;
unsigned char __RPC_FAR *pszString;
RPC_STATUS _Status;

((void)(_Status));
NdrServerInitializeNew(
_pRpcMessage,
&_StubMsg,
&sample1_StubDesc);

( unsigned char __RPC_FAR * )pszString = 0;
RpcTryFinally
{
RpcTryExcept
{
if ( (_pRpcMessage->DataRepresentation & 0X0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION )
NdrConvert( (PMIDL_STUB_MESSAGE) &_StubMsg, (PFORMAT_STRING) &__MIDL_ProcFormatString.Format[0] );

NdrConformantStringUnmarshall( (PMIDL_STUB_MESSAGE) &_StubMsg,
(unsigned char __RPC_FAR * __RPC_FAR *)&pszString,
(PFORMAT_STRING) &__MIDL_TypeFormatString.Format[4],
(unsigned char)0 );

if(_StubMsg.Buffer > _StubMsg.BufferEnd)
{
RpcRaiseException(RPC_X_BAD_STUB_DATA);
}
}
RpcExcept( RPC_BAD_STUB_DATA_EXCEPTION_FILTER )
{
RpcRaiseException(RPC_X_BAD_STUB_DATA);
}
RpcEndExcept

_RetVal = PrintString(pszString);

_StubMsg.BufferLength = 4U;
_StubMsg.BufferLength += 16;

_pRpcMessage->BufferLength = _StubMsg.BufferLength;

_Status = I_RpcGetBuffer( _pRpcMessage );
if ( _Status )
RpcRaiseException( _Status );

_StubMsg.Buffer = (unsigned char __RPC_FAR *) _pRpcMessage->Buffer;

*(( int __RPC_FAR * )_StubMsg.Buffer)++ = _RetVal;

}
RpcFinally
{
}
RpcEndFinally
_pRpcMessage->BufferLength =
(unsigned int)((long)_StubMsg.Buffer - (long)_pRpcMessage->Buffer);

}

void __RPC_STUB
sample1_ShutdownRPCServer(
PRPC_MESSAGE _pRpcMessage )
{
MIDL_STUB_MESSAGE _StubMsg;
RPC_STATUS _Status;

((void)(_Status));
NdrServerInitializeNew(
_pRpcMessage,
&_StubMsg,
&sample1_StubDesc);

RpcTryFinally
{
RpcTryExcept
{
if(_StubMsg.Buffer > _StubMsg.BufferEnd)
{
RpcRaiseException(RPC_X_BAD_STUB_DATA);
}
}
RpcExcept( RPC_BAD_STUB_DATA_EXCEPTION_FILTER )
{
RpcRaiseException(RPC_X_BAD_STUB_DATA);
}
RpcEndExcept

ShutdownRPCServer();

}
RpcFinally
{
}
RpcEndFinally
_pRpcMessage->BufferLength =
(unsigned int)((long)_StubMsg.Buffer - (long)_pRpcMessage->Buffer);

}


static const MIDL_STUB_DESC sample1_StubDesc =
{
(void __RPC_FAR *)& sample1___RpcServerInterface,
MIDL_user_allocate,
MIDL_user_free,
0,
0,
0,
0,
0,
__MIDL_TypeFormatString.Format,
1,
/* -error bounds_check flag */
0x10001,
/* Ndr library version */
0,
0x50100a4,
/* MIDL Version 5.1.164 */
0,
0,
0,
/* notify & notify_flag routine table */
1,
/* Flags */
0,
/* Reserved3 */
0,
/* Reserved4 */
0
/* Reserved5 */
};

static RPC_DISPATCH_FUNCTION sample1_table[] =
{
sample1_PrintString,
sample1_ShutdownRPCServer,
0
};
RPC_DISPATCH_TABLE sample1_v1_0_DispatchTable =
{
2,
sample1_table
};

#if !defined(__RPC_WIN32__)
#error Invalid build platform for this stub.
#endif

static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =
{
0,
{

0x4d,
/* FC_IN_PARAM */
#ifndef _ALPHA_
0x1,
/* x86, MIPS & PPC Stack size = 1 */
#else
0x2,
/* Alpha Stack size = 2 */
#endif
/* 2 */ NdrFcShort( 0x2 ), /* Type Offset=2 */
/* 4 */ 0x53, /* FC_RETURN_PARAM_BASETYPE */
0x8,
/* FC_LONG */
/* 6 */ 0x5b, /* FC_END */
0x5c,
/* FC_PAD */

0x0
}
};

static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =
{
0,
{
NdrFcShort( 0x0 ),
/* 0 */
/* 2 */
0x11, 0x8,
/* FC_RP [simple_pointer] */
/* 4 */
0x22,
/* FC_C_CSTRING */
0x5c,
/* FC_PAD */

0x0
}
};

 

 

 

/* file: sample1c.c */
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include "sample1.h"

void main()
{
RPC_STATUS status;
unsigned char * pszProtocolSequence = "ncacn_ip_tcp";
unsigned char * pszNetworkAddress = "enzo";
unsigned char * pszEndpoint = "8125";

unsigned char * pszOptions = NULL;
unsigned char * pszStringBinding = NULL;

unsigned long ulCode;

unsigned char * pszUuid = NULL;

status = RpcStringBindingCompose(pszUuid,
pszProtocolSequence,
pszNetworkAddress,
pszEndpoint,
pszOptions,
&pszStringBinding);

printf( "RpcStringBindingCompose ( pszUuid =%s )", pszUuid );
printf( "RpcStringBindingCompose ( pszStringBinding =%s )", pszStringBinding );

if (status)
{
printf( "[Errore] RpcStringBindingCompose ( status =%x %d )", status, status );
exit(status);
}


status = RpcBindingFromStringBinding(pszStringBinding,
&sample1_ifHandle);

if (status)
{
printf( "[Errore] RpcBindingFromStringBinding ( status =%x %d )", status, status );
exit(status);
}


RpcTryExcept
{
char cmd_line[200];

while(1)
{
gets( cmd_line );
PrintString( cmd_line);
if( strcmp( cmd_line, "quit") == 0 ) break;
else
if( strcmp( cmd_line, "shutdown") == 0 )
{
ShutdownRPCServer();
break;
}
else
if( strcmp( cmd_line, "dummy") == 0 )
{
status = RpcBindingFromStringBinding(pszStringBinding,
&dummy1_ifHandle);
if (status)
printf( "[Errore][dummy] RpcBindingFromStringBinding ( status =%x %d )", status, status );
DummyTest( cmd_line );
status = RpcBindingFree( &dummy1_ifHandle );
if (status)
printf( "[Errore][dummy] RpcBindingFree ( status =%x %d )", status, status );
}
}

}
RpcExcept(1)
{
ulCode = RpcExceptionCode();
printf("Runtime reported exception 0x%lx = %ld\n", ulCode, ulCode);
}
RpcEndExcept

status = RpcStringFree(&pszStringBinding);

if (status)
{
printf( "[Errore] RpcStringFree ( status =%x %d )", status, status );
exit(status);
}

status = RpcBindingFree(&sample1_ifHandle);

if (status)
{
printf( "[Errore] RpcBindingFree ( status =%x %d )", status, status );
exit(status);
}

exit(0);

}
// end main()


/*********************************************************************/
/* MIDL allocate and free */
/*********************************************************************/

void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
{
printf( "midl_user_allocate(%d)", len );
return(malloc(len));
}

void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
{
printf( "midl_user_free(%x)", ptr );
free(ptr);
}


/* file: sample1s.c */
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include "sample1.h"

void main()
{
RPC_STATUS status;
unsigned char * pszSecurity = NULL;

unsigned char * pszProtocolSequence = "ncacn_ip_tcp";
unsigned char * pszEndpoint = "8125";

unsigned int cMinCalls = 1;
unsigned int cMaxCalls = 20;
unsigned int fDontWait = FALSE;

status = RpcServerUseProtseqEp(pszProtocolSequence,
cMaxCalls,
pszEndpoint,
pszSecurity);

if (status)
{
printf( "[Errore] RpcServerUseProtseqEp ( status =%x %d )", status, status );
if( status == RPC_S_OK ) printf( "Success \n" );
else
if( status == RPC_S_PROTSEQ_NOT_SUPPORTED ) printf( "RPC_S_PROTSEQ_NOT_SUPPORTED \n" );
else
if( status == RPC_S_INVALID_RPC_PROTSEQ ) printf( "RPC_S_INVALID_RPC_PROTSEQ \n" );
else
if( status == RPC_S_INVALID_ENDPOINT_FORMAT ) printf( "RPC_S_INVALID_ENDPOINT_FORMAT \n" );
else
if( status == RPC_S_OUT_OF_MEMORY ) printf( "RPC_S_OUT_OF_MEMORY \n" );
else
if( status == RPC_S_DUPLICATE_ENDPOINT ) printf( "RPC_S_DUPLICATE_ENDPOINT \n" );
else
if( status == RPC_S_INVALID_SECURITY_DESC ) printf( "RPC_S_INVALID_SECURITY_DESC \n" );

exit(status);
}

status = RpcServerRegisterIf(sample1_v1_0_s_ifspec,  NULL,  NULL);

if (status)
{
    printf( "[Errore] RpcServerRegisterIf ( status = %x %d )", status, status );
    exit(status);
}

status = RpcServerListen(cMinCalls, cMaxCalls, fDontWait);

if (status)
{
    printf( "[Errore] RpcServerListen ( status = %x %d )", status, status );
    exit(status);
}

}
// end main()

/******************************************************/
/* MIDL allocate and free */
/******************************************************/

void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
{
     printf( "midl_user_allocate(%d)", len );
     return(malloc(len));
}

void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
{
      printf( "midl_user_free(%x)", ptr );
      free(ptr);
}


 

 

 

 

   if you have some suggestion or question about this program please mail me at enzo.arlati@libero.it

Main index 
NEWS

 

Last update:   30-03-2003

Hosted by :  
Xoom