-1

Before I ask the main question, I have two existing client/server win32 projects based on sockets in which the client sends a string request for the server and receives the result as a string using socket functions i.e. send(), recv()

a part of the server code (currently still based on sockets)

struct client_ctx
{
    int socket;
    CHAR buf_recv[MAX_SEND_BUF_SIZE]; // receive buffer
    CHAR buf_send[MAX_SEND_BUF_SIZE]; // send buffer
    unsigned int sz_recv; // size of recv buffer
    unsigned int sz_send_total; // size of send buffer
    unsigned int sz_send; // size of data send
                          // OVERLAPPED structures for notifications of completition 
    OVERLAPPED overlap_recv;
    OVERLAPPED overlap_send;
    OVERLAPPED overlap_cancel;
    DWORD flags_recv; // Flags for WSARecv
};
struct client_ctx g_ctxs[1 + MAX_CLIENTS];

void schedule_write(DWORD idx)
{
    WSABUF buf; buf.buf = g_ctxs[idx].buf_send + g_ctxs[idx].sz_send;
    buf.len = g_ctxs[idx].sz_send_total - g_ctxs[idx].sz_send;
    memset(&g_ctxs[idx].overlap_send, 0, sizeof(OVERLAPPED));
    WSASend(g_ctxs[idx].socket, &buf, 1, NULL, 0, &g_ctxs[idx].overlap_send, NULL);
}

And using the above functions I send the requested data to the client

The data I send from the server

static class SystemInfo{
public :
    static std::string GetOSVersion();
    static std::string GetCurrentTimeStr();
    static std::string GetTimeSinceStartStr();
    static std::string GetFreeMemoryStr();
    static std::string GetFreeSpaceStr();
    static std::string CheckAccess();
    static std::string CheckKeyFileDirectoryAccessRights(wchar_t *char_path, wchar_t *char_buf);
    static std::string UserNameFromSid(PSID userSid);
    static BOOL FileOrDirectoryExists(LPCTSTR szPath);
};

And the question is: is there any guide on how can I use the midl compiler to be able to represent the methods from SystemInfo class as procedures that can be called remotely? I can't find any manual of How to connect the existing functions with the remote procedure calls (and use them from the client side in my case)

Ivan Silkin
  • 381
  • 1
  • 7
  • 15
  • Not sure exactly what you're after. You want to use an .IDL to model your SystemInfo class? What are you going to do with that? What's the relation with sockets? Do you need COM? – Simon Mourier Nov 13 '19 at 16:00
  • @Simon Mourier, I need to replace the socket calls with the RPC methods and calls – Ivan Silkin Nov 13 '19 at 20:27
  • To you want to completely remove sockets from your program and use RPC instead? – Simon Mourier Nov 13 '19 at 21:16
  • @Simon Mourier, yeah, I clarified the title. That's what I question – Ivan Silkin Nov 13 '19 at 21:48
  • Microsoft provides samples for IDL and RPC: https://learn.microsoft.com/en-us/windows/win32/rpc/examples located now on github: https://github.com/microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/netds/rpc but note this is different from COM. COM has a dependency on RPC. But RPC is a technology for itself. – Simon Mourier Nov 14 '19 at 07:26

1 Answers1

0

You aren't going to be able to hook the client calls directly to existing server functions. Even when implicit binding handles are used on the client side the actual server function gets a binding handle (otherwise the server wouldn't be able to handle multiple clients). Because of that the signatures simply aren't going to match.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
  • I already have an existing solution with a file for both the server and the client with a header in the file saying "File created by MIDL compiler version 8.00.0603", included in my second external example project, before using "RpcServerUseProtseqEp(), RpcServerRegisterIf2(), RpcServerListen()", allowing the client to call server side functions by using *NdrClientCall2()* (rpcndr.h). And I'm unable to find a guide/manual for using the midl compiler, it must be just a command-line utility or am I missing something here? I am looking for some information about midl for newbies (beginners) – Ivan Silkin Nov 13 '19 at 21:59