I want to define a new function inside my RPC code. I am new to this, so I just duplicate the function Output and rename it as Output2. But when I run the EXE, the Output function is always being called, even though I really called Output2. Need guide..
This is a code that I found on the net. It is somehow a stub file I think..
Here is the code I am working with:
void Output(
/* [string][in] */ const char *szOutput)
{
NdrClientCall2(
( PMIDL_STUB_DESC )&Example1_StubDesc,
(PFORMAT_STRING) &Example1__MIDL_ProcFormatString.Format[0],
( unsigned char * )&szOutput);
}
void Output2( const char *test) // <---- I added this definition
{
NdrClientCall2(
( PMIDL_STUB_DESC )&Example1_StubDesc,
(PFORMAT_STRING) &Example1__MIDL_ProcFormatString.Format[0],
( unsigned char * )&test);
}
The diagram on this page might help you understand the following explanation. What you’ve done is created a second client stub called “Output2” but that new client stub calls the same server stub as “Output” does (because it passes the same values to parameters one and two of NdrClientCall2) so the server stub ends up calling the same server application function.
Assuming your RPC application is sensibly constructed, you should not be editing files containing NdrClientCall2 calls. The client stub files are normally generated by the MIDL compiler. You need to find your application’s IDL file (and possibly the associated ACF file) and add a definition for Output2 to your IDL. Then, when you rebuild your client project, the MIDL compiler should compile your newly modified IDL file (and the ACF file if necessary) and generate a new client stub.
Similarly, when you compile your server project (using the same IDL) the MIDL compiler will generate new server stub files. Depending on how your server application is written you may have to edit the server stub file to wire up the stub to the actual implementation of the function.
Some of the articles here may be useful but if you don’t understand how RPC works you may be biting off more than you can chew.