Search code examples
c++serverrpc

RPC C++ server side dynamic endpoint


I'm doing a rpc server/client project. The hardcoded endpoint version works well and now I want to let the server to dynamically setup the endpoint.

I did some research, and I need to use RpcNsBindingExport() function to export the name service database for server, then client can get the available binding information. Server code can compile but there is a error when I run the server. The error message says that: LNK2019 unresolved external symbol __imp__RpcNsBindingExportA@20 referenced in function _main

Here is the code for my server.cpp:

main(){
    //choose protocol sequence
    status = RpcServerUseProtseq(
        pszProtocolSequence,
        RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
        pszSecurity
    );
    if (status) exit(status);

    //get binding info for server
    RPC_BINDING_VECTOR *binding_vector;
    status = RpcServerInqBindings(&binding_vector);

    //Export to a name service database for advertising
    status = RpcNsBindingExport(
        RPC_C_NS_SYNTAX_DEFAULT,
        (unsigned char *)"hostname",
        midl_v1_0_s_ifspec,
        binding_vector,
        NULL
    );

    if (status) exit(status);

    //reg server
    status = RpcEpRegister(
        hello_v1_0_s_ifspec,
        binding_vector,
        NULL,
        (unsigned char *)annotion
    );

    //listen
    if (status) exit(status);

    status = RpcServerListen(cMinCalls,
        RPC_C_LISTEN_MAX_CALLS_DEFAULT,
        fDontWait);

    if (status) exit(status);
}

Both rpcrt4.lib and rpcns4.lib are linked in the project. I don't know if there is anything missing, or maybe the usage of the RpcNsBindingExport() is wrong.

Thanks for any suggestions and ideas.


Solution

  • Usually, Error LNK2019 unresolved external symbol happens when the compiler cannot find the lib file. Try to put the full path of the .lib files in the Additional dependencies under linker drop down. And Check for build option (x32 or x64). The x32 lib cannot work with x64 application or else.