Reputation: 191
Let me attempt to briefly explain what I am trying to accomplish here...
I have used the Remote Procedure call (RPC) approach to develop a Client application in C++ and a Server application also in C++. The Client is 64 bit and the Server is 32 bit. The goal of this effort was to use the Client to pass variables to functions on the Server side. Then the Server would use a 32 bit .dll to process the data that was received and return the outputted values back to the Client. This process is working very well and I couldn't be happier with it.
I am working with a 64 bit application that was developed in C# and has a static class for sending variables to a .dll and returning the values outputted. Because this application is 64 bit it cannot be connected to the 32 bit .dll (duh) that is required for these computations.
Now for my question...
Is there any way I can keep the process I have already developed in C++ and access the 32 bit Server from the 64 bit C# project? Is there a better approach for this all together?
EDIT: I should also include I am using the rpcrt4.lib and here is my Client sample code.
int main()
{
RPC_STATUS status;
unsigned char* szStringBinding = NULL;
char temppath[MAX_PATH] = {0};
// Creates a string binding handle.
// This function is nothing more than a printf.
// Connection is not done here.
status = RpcStringBindingCompose(
NULL, // UUID to bind to.
reinterpret_cast<unsigned char*>("ncacn_ip_tcp"), // Use TCP/IP
// protocol.
reinterpret_cast<unsigned char*>("localhost"), // TCP/IP network
// address to use.
reinterpret_cast<unsigned char*>("4747"), // 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.
&hRPCProjectBinding); // Put the result in the implicit binding
// handle defined in the IDL file.
if (status)
exit(status);
RpcTryExcept
{
// Calls the RPC function. The hRPCProjectBinding binding handle
// is used implicitly.
// Connection is done here.
Output((unsigned char*)"Implcicit RPC Server Call from Client ");
system("PAUSE");
ShutDown();
}
RpcExcept(1)
{
std::cerr << "Runtime reported exception " << RpcExceptionCode()
<< std::endl;
}
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(
&hRPCProjectBinding); // Frees the implicit binding handle defined in
// the IDL file.
if (status)
exit(status);
}
This is the tutorial I followed to develop this project:
Any reference materials, input or criticism is greatly appreciated.
Thanks for taking the time to read this and for any guidance.
Upvotes: 0
Views: 725
Reputation: 15172
Assuming you are talking about MS-RPC the easy way would be to write an interop DLL in C++ that makes the RPC calls. Have that DLL include the *_c.c and *_h.h outputs of midl.exe and then add code to set up the binding handles etc.
This will require a fair bit of translation in the C++ code (from .net types to types that can go across the wire) but will take the least immediate effort.
More extreme options would be to re-write your RPC code to be pure .net, at that point there are plenty of remoting options available.
Upvotes: 1