1

I'm having an issue with retrieving an xml portion of a message using a vendor's api. As an example of what works: getDestination(void* message , void* destination, void* size)

vendordestinationtype_t dest;
getDestination(msg_p, &dest, 16);
printf("Received message. (Destination: %s).\n", dest.dest);

produces: Received message. (Destination: some destination).

Hoever to retrieve the XML portion of the message it requires a function which is getXmlPtr(void* msg, void** xml_ptr, void* xml_length)

char ptr[10000];
int size;
getXmlPtr(msg_p, (void**)&ptr, &size);
printf("Received message. (XML: %s).\n", ptr);

So the question is, how do I declare and pass ptr in such a way that I can get the xml information out (the vendor's documentation is really bad) it mostly says that the argument should be a pointer to the application pointer to fill in with the message XML data pointer on return. The programmer may cast the returned void pointer to any reference suitable for the application.

Buraan
  • 13
  • 3

2 Answers2

0

Well, you declare pointer to void as a pointer to void: void *ptr;.

Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151
  • I guess the cast is then done by the printf statement? I guess that's what I was doing wrong when I was going at it before like that. Thanks! – Buraan Jan 06 '12 at 14:50
  • @Buraan That really depends on what you want to do with it, but yeah. Also you can cast on the call, but you need a compatible type (pointer to array and pointer to pointer are two different things). – Šimon Tóth Jan 06 '12 at 14:53
0

void** means you're passing a pointer by reference; presumably, the function will modify this to point to wherever it the XML data is stored. So you need a pointer, not an array:

void * ptr;
int size;
getXMLPtr(msg_p, &ptr, &size);
Mike Seymour
  • 249,747
  • 28
  • 448
  • 644