|
You're calling a C function. In C, char* or "const char*" are similar to
passing this:
D path 640A
The CONST keyword means nothing at this point.
However, in your case, it is expecting a null-terminated string. RPG IV
automatically creates these strings when you add OPTIONS(*STRING) to a
pointer parameter. So first we have to convert the above to a pointer, as
follows:
D path *
This is okay if we pass %addr(myField), but if we only pass this, then we
also need to include the null terminator, X'00'. Not very pretty, so we let
RPG do it for us.
D path * Options(*STRING)
Hmmm... something's not working, what is it? Well in the called procedure it
is looking at the address of the value passed in, and taking the information
in that address, as data. Unfortunately since RPG passes-by-reference, the
data the called routine is looking at is actually the pointer, not the value
we passed to it.
So we need to make it more C-friendly, by passing the address "by value",
D path * VALUE Options(*STRING)
Now suddenly it works, but we still have an issue.
When we call this procedure, we should use %trimR(myPath) to delete any
trailing blanks in the path name.
What if we used this instead?
D path * Const Options(*STRING)
It is these same as without the CONST keyword, pass-by-reference and you'll
get crap.
-Bob Cozzi
www.RPGxTools.com
RPG xTools - Enjoy programming again.
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of darren@xxxxxxxxx
Sent: Friday, January 27, 2006 9:09 AM
To: rpg400-l@xxxxxxxxxxxx
Subject: CONST vs. VALUE on a pointer parameter
I attempted to call the Qp0lGetAttr API to get the creation date of a file
in the IFS. I used the following prototype.
D Qp0lGetAttr PR 10I 0 ExtProc('Qp0lGetAttr')
D path * Const
D AttArrPtr * Const
D BuffPtr * Const
D BuffLenSent 10U 0 Const
D BuffLenNeed 10U 0
D BuffLenRet 10U 0
D FollowLink 10U 0 Value
The above did not work, apparently because I had used Const. The program
compiles fine both ways, but the API returns a -1 indicating that some kind
of error occurred. I can toggle the 'path' parameter from Value to Const
and get it to fail, with everything else as shown below. My reason for
using Const was to document that the variable being pointed to was an Input
only variable per the API's specs. Can someone in the know, educate me as
to the different between Const and Value in this case?
D Qp0lGetAttr PR 10I 0 ExtProc('Qp0lGetAttr')
D path * Value
D AttArrPtr * Value
D BuffPtr * Value
D BuffLenSent 10U 0 Value
D BuffLenNeed 10U 0
D BuffLenRet 10U 0
D FollowLink 10U 0 Value
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.