I got error while I was tying to pass structure from RPC client to server. Client calls Output3 procedure.

Definition in IDL:

struct BarStruct
{
  byte a;
  int b;
  byte c;
  char* d;
  char* ddd;
};

void Output3([in] handle_t hBinding, [in, out] struct BarStruct* b);

Generated in header:

struct BarStruct
    {
    byte a;
    int b;
    byte c;
    char *d;
    char *ddd;
    } ;

void Output3( 
    /* [in] */ handle_t hBinding,
    /* [out][in] */ struct BarStruct *b);

implementation in server side:

void Output3(handle_t hBinding, struct BarStruct * b)
{
    std::cout << "a=" << b->a << std::endl;
}

Client side code:

  BarStruct b;
  b.a=10;

  std::cout<<"Output3"<<std::endl ;
  Output3(hBinding, &b);

What might be wrong?

有帮助吗?

解决方案

Your structure contains pointer to something, in the specific case pointer to char. When you want to transfer this to another process you have to keep in mind that a pointer is just and address value. When you want to pass the data where the pointer points to you need something different like a conformant array.

The basic idea is that you have to pass the length of the array that is address by the pointer.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top