ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ API Support » Put C structure object into queue

Post new topic  Reply to topic
 Put C structure object into queue « View previous topic :: View next topic » 
Author Message
keerthikumar
PostPosted: Mon May 15, 2006 10:35 pm    Post subject: Put C structure object into queue Reply with quote

Novice

Joined: 23 Nov 2005
Posts: 13

hello

I want to put a C structure object into queue.

I have the data stored in a C structure object .
What attributes in MQPUT api should i change so that i can send that structure into the queue


thanks and regards
Back to top
View user's profile Send private message
keerthikumar
PostPosted: Mon May 15, 2006 11:24 pm    Post subject: Reply with quote

Novice

Joined: 23 Nov 2005
Posts: 13

I tried to use memcpy() function to copy the contents of the struct to unsigned char array but I am not able to copy entire data

so How can i send the entire information of the struct to the queue
Back to top
View user's profile Send private message
Nigelg
PostPosted: Mon May 15, 2006 11:26 pm    Post subject: Reply with quote

Grand Master

Joined: 02 Aug 2004
Posts: 1046

In the MQPUT API there are 2 arguments which relate to the data, a char * which is a pointer to the start of the data, and a long which is the length of the data.

Pass your structure to MQPUT by casting a pointer to it to a char *, and set the length to be sizeof your structure.
_________________
MQSeries.net helps those who help themselves..
Back to top
View user's profile Send private message
bob_buxton
PostPosted: Tue May 16, 2006 12:45 am    Post subject: Reply with quote

Master

Joined: 23 Aug 2001
Posts: 266
Location: England

Does your structure contain any non character data and could your message be sent to a queue manager on a different platfom or to a Java application?

If the answer is yes you will need to consider format conversion.
You would need to invent a format name to put in the MQMD format field and provide a format conversion exit on your receiving system to convert data to the appropriate encoding and code page.
_________________
Bob Buxton
Ex-Websphere MQ Development
Back to top
View user's profile Send private message
keerthikumar
PostPosted: Tue May 16, 2006 1:17 am    Post subject: Reply with quote

Novice

Joined: 23 Nov 2005
Posts: 13

yes my structure contains non character data also

struct sAccountDetails
{
char acAccType[10];
double fbalance;

};

struct sPersonalDetails
{
char acCustID[10];
char acCustFirstName[20];
char acCustLastName[20];
char acCustDOB[15];
char acCustAddress[100];
char acCustCity[15];
char acCustPincode[10];
char acCustPhone[12];

};
struct sCustomerDetails
{
struct sPersonalDetails personaldetails;
struct sAccountDetails accountdetails;
}custdetails;

this is my structure.

i tried to do memcpy as

unsigned char buffer[500];
struct sCustomerDetails * temp;
temp=&custdetails;
memcpy(buffer,temp,sizeof(custdetails));


but I could not copy entire structure only custdetails.sPersonalDetails.acCustID was only copied

how should I proceed now
Back to top
View user's profile Send private message
keerthikumar
PostPosted: Tue May 16, 2006 1:25 am    Post subject: Reply with quote

Novice

Joined: 23 Nov 2005
Posts: 13

MQMD md = {MQMD_DEFAULT}; /* Message Descriptor */

memcpy(md.Format, /* character string format */
MQFMT_STRING, (size_t)MQ_FORMAT_LENGTH);

This the message format i have chosen


MQPUT(Hcon, /* connection handle */
Hobj, /* object handle */
&md, /* message descriptor */
&pmo, /* default options (datagram) */
messlen, /* message length */
buffer, /* message buffer */
&CompCode, /* completion code */
&Reason); /* reason code */


What should i change so that i can send the structure

thanks and regards
Back to top
View user's profile Send private message
mvic
PostPosted: Tue May 16, 2006 1:53 am    Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

keerthikumar wrote:
What should i change so that i can send the structure

Don't use MQFMT_STRING; this indicates to MQ that your message contains character data encoded in the CCSID you store in md.CodedCharSetId

Here's a good place to start reading about sending/converting known-user-format messages : http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/topic/com.ibm.mq.csqzak.doc/convx.htm

(NB. If you are always sending between similar machines, you could plan not to use data conversion at all. This is a detail I didn't see in the problem description).

EDIT: tiny editorial change to paragraph 1


Last edited by mvic on Tue May 16, 2006 8:03 am; edited 1 time in total
Back to top
View user's profile Send private message
EddieA
PostPosted: Tue May 16, 2006 7:53 am    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

Or, if you do need to convert the data between code pages, you could convert the non-character data to character for the "journey", and then convert back at the other end.

Cheers,
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue May 16, 2006 9:18 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

you could convert the non-character data to character for the "journey", and then convert back at the other end.
Or instead of building a language and endian-specific message, you could do something more platform neutral like represent the data as XML, and write it to the message as a string.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Tue May 16, 2006 10:08 pm    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

keerthikumar wrote:
struct sCustomerDetails
{
struct sPersonalDetails personaldetails;
struct sAccountDetails accountdetails;
}custdetails;

...

unsigned char buffer[500];
struct sCustomerDetails * temp;
temp=&custdetails;

memcpy(buffer,temp,sizeof(custdetails));

Hi,

This is a C programming error and has nothing to do with MQ. Any decent debugger would have shown the result of sizeof(custdetails) and you would known what the problem was (hopefully known).

keerthikumar wrote:
but I could not copy entire structure only custdetails.sPersonalDetails.acCustID was only copied

Impossible. That field has a length of 10. You are actually ONLY copying 8 bytes.

Dig out your C programming references and look up struct and struct within a struct. This will lead you to the answer.

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
tleichen
PostPosted: Wed May 17, 2006 11:13 am    Post subject: Reply with quote

Yatiri

Joined: 11 Apr 2005
Posts: 663
Location: Center of the USA

I suppose now we have to teach the inexperienced how to write code too?
_________________
IBM Certified MQSeries Specialist
IBM Certified MQSeries Developer
Back to top
View user's profile Send private message
leehairy
PostPosted: Tue Aug 08, 2006 3:32 am    Post subject: Reply with quote

Novice

Joined: 04 Aug 2006
Posts: 13

I dont get the last comment..

RogerLacroix - What would make you think that structs in structs would not be the cumulative size of a structure?

The struct does not contain pointers to other structures. Did you misread?


sizeof(custDetails) is 232 == sizeof(struct sCustomerDetails)
which is correct..


Quote:
keerthikumar wrote:
but I could not copy entire structure only custdetails.sPersonalDetails.acCustID was only copied


Do you mean only 10 bytes where copied to char *buffer or only 10 bytes appeared on the queue?

My little test harness based seems to work fine ...

Code:
// con1.cpp : Defines the entry point for the console application.
//

#include <string.h>

struct sAccountDetails
{
   char acAccType[10];
   double fbalance;
};

struct sPersonalDetails
{
   char acCustID[10];
   char acCustFirstName[20];
   char acCustLastName[20];
   char acCustDOB[15];
   char acCustAddress[100];
   char acCustCity[15];
   char acCustPincode[10];
   char acCustPhone[12];

};

struct sCustomerDetails
{
   struct sPersonalDetails personaldetails;
   struct sAccountDetails accountdetails;
}custdetails;









int _tmain(int argc, _TCHAR* argv[])
{
   strcpy(custdetails.accountdetails.acAccType, "10");
   custdetails.accountdetails.fbalance  = 10.0f;

   strcpy(custdetails.personaldetails.acCustAddress, "add1");
   strcpy(custdetails.personaldetails.acCustFirstName, "first");
   strcpy(custdetails.personaldetails.acCustLastName, "last");
   strcpy(custdetails.personaldetails.acCustDOB, "13-15-03");
   strcpy(custdetails.personaldetails.acCustID, "10");
   strcpy(custdetails.personaldetails.acCustCity, "bighton");
   strcpy(custdetails.personaldetails.acCustPincode, "4738");
   strcpy(custdetails.personaldetails.acCustPhone, "911");

   unsigned char buffer[500];
   memcpy(buffer,(char *)(&custdetails),sizeof(custdetails));

   int l = (int)sizeof(sCustomerDetails);
   int x = (int)sizeof(custdetails);

   // unpack ...
   struct sCustomerDetails unpack = { 0x00 };

   memcpy((char *)&unpack, buffer, sizeof(struct sCustomerDetails));

   return 0;
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » Put C structure object into queue
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.