是否可以连接到32位C++;来自C#应用程序的RPC服务器应用程序

是否可以连接到32位C++;来自C#应用程序的RPC服务器应用程序,c#,c++,client-server,rpc,C#,C++,Client Server,Rpc,让我试着简单地解释一下我在这里要实现的目标 我使用了远程过程调用(RPC)方法来开发C++中的客户端应用程序和C++中的服务器应用程序。客户端为64位,服务器为32位。这项工作的目标是使用客户端将变量传递给服务器端的函数。然后服务器将使用一个32位的.dll来处理接收到的数据,并将输出的值返回给客户端。这个过程运行得很好,我非常高兴 我正在使用一个用C#开发的64位应用程序,它有一个静态类,用于将变量发送到.dll并返回输出的值。由于此应用程序是64位的,因此无法连接到这些计算所需的32位.dl

让我试着简单地解释一下我在这里要实现的目标

我使用了远程过程调用(RPC)方法来开发C++中的客户端应用程序和C++中的服务器应用程序。客户端为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);
}
intmain()
{
RPC_状态;
无符号字符*szStringBinding=NULL;
char temppath[MAX_PATH]={0};
//创建字符串绑定句柄。
//这个函数只不过是一个printf。
//这里没有连接。
状态=RpcStringBindingCompose(
NULL,//要绑定到的UUID。
重新解释强制转换(“ncacn\U ip\U tcp”),//使用tcp/ip
//协议。
重新解释广播(“本地主机”),//TCP/IP网络
//要使用的地址。
重新解释_cast(“4747”),//要使用的TCP/IP端口。
NULL,//要使用的协议相关网络选项。
&szStringBinding);//字符串绑定输出。
如果(状态)
退出(状态);
//验证字符串绑定句柄的格式并进行转换
//它是一个绑定句柄。
//这里也没有连接。
状态=RpcBindingFromStringBinding(
szStringBinding,//要验证的字符串绑定。
&hRPCProjectBinding);//将结果放入隐式绑定中
//IDL文件中定义的句柄。
如果(状态)
退出(状态);
RpcTryExcept
{
//调用RPC函数。hRPCProjectBinding绑定句柄
//是隐式使用的。
//连接在这里完成。
输出((unsigned char*)“来自客户端的Implcicit RPC服务器调用”);
系统(“暂停”);
关机();
}
RpcExcept(1)
{

STR::CERP(Pr>)假设你在谈论MS-RPC,很简单的方法是在C++中编写一个互操作的DLL来实现RPC调用。DLL包含MyL.EXE的**C.C和*.H.H输出,然后添加代码来设置绑定句柄等。

这将需要在C++代码中进行一次公平的翻译(从.NET类型到可以跨线的类型),但是将尽可能少的立即努力。


更极端的选择是将您的RPC代码重新编写为纯.net,此时有很多远程处理选项可用。

您应该指定您正在使用的RPC框架,可能会给我们几行客户端和服务器代码,以查看示例调用。据我所知,还没有std::RPC_调用;-)哈哈@Jeffrey got对不起,请您稍等。您不能在同一进程中混合使用32位和64位代码。您需要一个32位进程来加载32位DLL。假设我正确理解您的情况,听起来您可以构建一个包装器,并使用一些IPC机制从64位服务器与它进行通信。@MilesBudnek服务器已经是32位的,ClieNT是64位。我使用上面所解释的方法来获得一个32位DLL的值,并将输出返回到C++中的客户端。它正在工作。我需要将功能转移到C语言应用程序。我一直在研究使用包装器,我想这就是我要采用的路线。我只是想知道这种方法是否是最好的方法。