让我尝试简要解释一下我要在这里完成的工作...
我已经使用了远程过程调用(RPC)方法来开发C ++中的Client应用程序和C ++中的Server应用程序。客户端是64位,服务器是32位。这项工作的目标是使用客户端将变量传递给服务器端的函数。然后,服务器将使用32位.dll来处理接收到的数据,并将输出的值返回给客户端。这个过程运行良好,我对此感到不满意。
我正在使用C#开发的64位应用程序,该应用程序具有用于将变量发送到.dll并返回输出值的静态类。由于此应用程序是64位的,因此无法连接到这些计算所需的32位.dll(duh)。
现在我的问题...
有什么方法可以保持已经用C ++开发的过程并从64位C#项目访问32位服务器?在一起是否有更好的方法?
编辑:我还应该包括我正在使用rpcrt4.lib,这是我的客户示例代码。
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);
}
这是我开发该项目所遵循的教程:
任何参考资料,建议或批评,我们将不胜感激。
感谢您抽出宝贵的时间阅读本文档以及获得任何指导。
假定您正在谈论MS-RPC,最简单的方法是用C ++编写一个进行RPC调用的互操作DLL。使该DLL包含midl.exe的* _c.c和* _h.h输出,然后添加代码以设置绑定句柄等。
这将需要在C ++代码中进行相当多的翻译(从.net类型到可以跨线使用的类型),但是将花费最少的立即工作。
更极端的选择是将您的RPC代码重写为纯.net,这时有很多可用的远程处理选项。