0

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?

vico
  • 17,051
  • 45
  • 159
  • 315

1 Answers1

0

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.

harper
  • 13,345
  • 8
  • 56
  • 105
  • Problem was in pointer, after removing d and ddd evrything goes fine. MSDN describes how to use arrays in function, but how to write conformant array for structure? – vico Mar 25 '14 at 15:16
  • You can embed the arrays in the structure instead the pointers. You will have to add a length field anyway. Since your member names are too anonymized I can't say if you already have something like a length field. – harper Mar 25 '14 at 15:41