Thanks Bryan. I'll check it out.


-----Original Message-----
From: c400-l-bounces+lim.hock-chai=usamobility.com@xxxxxxxxxxxx
[mailto:c400-l-bounces+lim.hock-chai=usamobility.com@xxxxxxxxxxxx] On
Behalf Of bryan dietz
Sent: Monday, June 09, 2008 8:50 AM
To: C programming iSeries / AS400
Subject: Re: [C400-L] Prototype *varsize field where CEEDOD is
usedinthecaller to determine the length

there are lots of C examples in the info center:

maybe this one will work:
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/s
qlp/rbafysystrigexample.htm

Bryan


On Mon, Jun 9, 2008 at 9:46 AM, Lim Hock-Chai
<Lim.Hock-Chai@xxxxxxxxxxxxxxx>
wrote:

Changing SNDMSG to use %str is probably not an option for me. This
procedure is being used by a lot of RPG applications already.

I might just need to call the QMHSNDPM api directly from the C
program.
Does anybody already has prototype and example for QMHSNDPM that can
share?

I'm a RPG programmer and is very weak in C language.

thanks

-----Original Message-----
From: c400-l-bounces+lim.hock-chai=usamobility.com@xxxxxxxxxxxx
[mailto:c400-l-bounces+lim.hock-chai <c400-l-bounces%2Blim.hock-chai>=

usamobility.com@xxxxxxxxxxxx] On Behalf Of Simon Coulter
Sent: Sunday, June 08, 2008 7:33 AM
To: C programming iSeries / AS400
Subject: Re: [C400-L] Prototype *varsize field where CEEDOD is used
inthecaller to determine the length


On 06/06/2008, at 11:46 PM, Lim Hock-Chai wrote:

I've already tried what you suggested. I was getting the CEE0502
error (Missing operational descriptor).

That's what I suspected. The C manual states that unspecified
parameter positions on a #pragma descriptor statement are treated as
void (therefore no descriptor is passed).


I tried below and the SNDMSG procedure is getting a lenght of 0 for
the 2nd parameter when calling CEEDOD:
#ifdef sndMsg_Prototype
typedef struct {
char value[10];
} sndMsg_msgID_T;

typedef struct {
char value[10];
} sndMsg_msgType_T;

typedef struct {
char value[10];
} sndMsg_msgFile_T;

typedef struct {
char value[10];
} sndMsg_msgLib_T;

typedef struct {
char value[10];
} sndMsg_msgQueue_T;

void
sndMsg(
const sndMsg_msgID_T *msgID,
const char *msgData,
const sndMsg_msgType_T *msgType,
const sndMsg_msgFile_T *msgFile,
const sndMsg_msgLib_T *msgLib,
const sndMsg_msgQueue_T *msgQueue);

#pragma map (sndMsg, "SNDMSG")
#pragma descriptor (void sndMsg(void, *)) #endif


The C program that call sndMsg looks like below:
char *msgData;
sndMsg_msgID_T msgID;
sndMsg_msgType_T msgType;

msgData = "Message Form TESTC";
memset(&msgID, ' ', sizeof(msgID));
memcpy(&msgID, "CPF9898",7);
memset(&msgType, ' ', sizeof(msgType)); memcpy(&msgType, "*ESCAPE",
7); sndMsg(&msgID, msgData, &msgType,0,0,0);

You're passing a pointer to a null-terminated string. As far as C is
concerned that's a pointer to an array of 1-byte elements.

The op-desc for such a thing is:

descType = 2 = Element

dataType = 3 = Null-Terminated string

Because a null-terminated string is passed no length value is passed
hence the 0 you experience.

You will have to use the %STR BIF to process it or count the
characters yourself.


________________________________

From: c400-l-bounces+lim.hock-chai=usamobility.com@xxxxxxxxxxxx on
behalf of Simon Coulter
Sent: Thu 6/5/2008 5:08 PM
To: C programming iSeries / AS400
Subject: Re: [C400-L] Prototype *varsize field where CEEDOD is used
in thecaller to determine the length




Not tested but see below:

On 06/06/2008, at 2:47 AM, Lim Hock-Chai wrote:

I've the following RPG export procedure, can someone help me
protoype this in C?
d SndMsg PR opdesc
d SndMsg PI opdesc
d MsgInId 10 const

A message ID is only 7 bytes.

d MsgInData 32766 const options
(*varsize:*nopass:*omit)
d MsgInType 10 const options(*nopass:*omit )
d MsgFile 10 const options(*nopass:*omit)
d MsgLib 10 const options(*nopass:*omit)
d MsgInQueue 10 const options(*nopass:*omit)

#pragma map (sndMsg, "SNDMSG")
void sndMsg( const char *, ... );

One required parameter, all others are optional.

To get C to pass descriptors:

#pragma descriptor (void sndMsg(*))

You can only specify a descriptor for defined parameters (i.e., not
optional ones). Even though you cannot specify a descriptor for the
optional parameters you will get a valid count (%parms). Not sure
what will happen if you try to retrieve a descriptor for an optional

parameter.


I tried below and is getting a CZM0879 compile error:

This is most likely caused by the prototype indicating a struct but
the #pragma says you want a string descriptor passed. A struct is
not a string.

#ifdef sndMsg_Prototype
typedef struct {
char value[10];
} sndMsg_msgID_T;


typedef struct {
char value[32766];
} sndMsg_msgData_T;

typedef struct {
char value[10];
} sndMsg_msgType_T;

typedef struct {
char value[10];
} sndMsg_msgFile_T;

typedef struct {
char value[10];
} sndMsg_msgLib_T;

typedef struct {
char value[10];
} sndMsg_msgQueue_T;


Why do this? The parameters are not structures in RPG so why force
them on the C programmer? C has no concept of fixed-length fields
anyway so the C programmer will have to ensure correct lengths and
padding unless your RPG uses the op-desc to handle NULL-terminated
strings.

You can't pass an op-desc for a structure anyway

Also C passes everything except arrays by value so passing a data
structure in this manner will likely cock things up.

void
sndMsg(
const sndMsg_msgID_T *msgID,
const sndMsg_msgData_T *msgData,
const sndMsg_msgType_T *msgType,
const sndMsg_msgFile_T *msgFile,
const sndMsg_msgLib_T *msgLib,
const sndMsg_msgQueue_T *msgQueue);

Close but:
1) All parameters are required whereas the RPG prototype has

only one required parameter.
2) Pointers to structs--weird from a C perspective.

#pragma map (sndMsg, "SNDMSG");

This is because RPG mono-cases procedure names. I would change that
on the RPG prototype:

d SndMsg PR opdesc extproc('sndMsg')

which will cause RPG to keep the case-sensitive name so other
languages won't have to map the name.

#pragma descriptor (void sndMsg(void,*))

This says no op-desc for first parm, op-desc for second, and no op-
desc for any others, which is not what you want.


#endif
--
This is the C programming iSeries / AS400 (C400-L) mailing list To
post a message email: C400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx Before posting, please take a

moment to review the archives at
http://archive.midrange.com/c400-l.



Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------



--
This is the C programming iSeries / AS400 (C400-L) mailing list To
post a message email: C400-L@xxxxxxxxxxxx To subscribe, unsubscribe,

or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/c400-l.



--
This is the C programming iSeries / AS400 (C400-L) mailing list To
post a message email: C400-L@xxxxxxxxxxxx To subscribe, unsubscribe,

or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/c400-l.


Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------



--
This is the C programming iSeries / AS400 (C400-L) mailing list To
post a message email: C400-L@xxxxxxxxxxxx To subscribe, unsubscribe,
or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/c400-l.

--
This is the C programming iSeries / AS400 (C400-L) mailing list To
post a message email: C400-L@xxxxxxxxxxxx To subscribe, unsubscribe,
or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/c400-l.





This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].