#include <stdio.h>
#include "..\RPC1_IDL\DoRPC.h"
int main()
{
RPC_STATUS status;
unsignedchar* szStringBinding = NULL;
// Creates a string binding handle.
// This function formats the passed values in a
// predefined format for use by RPC. Just like printf
// Connection is not done here.
status = RpcStringBindingCompose(
NULL, // UUID to bind to.
(unsignedchar*)("ncacn_ip_tcp"), // Use TCP/IP protocol.
(unsignedchar*)("localhost"), // TCP/IP network
(unsignedchar*)("1234"), // TCP/IP port to use.
NULL, // Protocol dependent network options to use.
&szStringBinding); // String binding output.
if (status)
exit(status);
// Validates the format of the string binding handle and converts
// it to a binding handle.
// Connection is not done here either.
status = RpcBindingFromStringBinding(
szStringBinding, // The string binding to validate.
&hDoRPCBinding); // Put the result in the implicit binding
// handle defined in the IDL file.
if(status)
{
exit(status);
}
RpcTryExcept
{
// Calls the RPC function. The hDoRPCBinding binding handle
// is used implicitly.
// Connection is done here.
constunsignedchar szMsg[] = "Client: I Can RPC Now!";
Show(szMsg);
}
RpcExcept(1)
{
printf("Runtime exception occured: %d\n",RpcExceptionCode());
}
RpcEndExcept
// Free the memory allocated by a string.
status = RpcStringFree(&szStringBinding); // String to be freed.
if(status)
{
exit(status);
}
// Releases binding handle resources and disconnects from the server.
status = RpcBindingFree(
&hDoRPCBinding); // Frees the implicit binding handle defined in
// the IDL file.
if (status)
{
exit(status);
}
system ("PAUSE");
return 0;
}
// Memory allocation function for RPC.
// The runtime uses these two functions for allocating/deallocating
// enough memory to pass the string to the server.
void* __RPC_USER midl_user_allocate(size_t size)
{
return malloc(size);
}
// Memory deallocation function for RPC.
void __RPC_USER midl_user_free(void* p)
{
free(p);
}
i debugged the program and found that the problem was with the line in the show function NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsignedchar __RPC_FAR *) _StubMsg.Buffer );
the file that the show function is from was automatically generated when i complied a idl file. i haven't changed any of the code from the website i linked in the first post. can you download the code and test it yourself?
This cannot be done by hand. RPC is done this way only. We create stubs and compile them into a C code, which generates server and client code. Then add your own code and lots of things I don't remember now..
I think this is more suitable to post in windows forum.