Re: An old C function problem revisited

new topic     » goto parent     » topic index » view thread      » older message » newer message

Al Getz wrote:
> Where is the documentation on this function?  If we could read it
> something may turn up.
> 
> Also, it is possible (although without doc's it's hard to say for sure)
> that you need to allocate your pointers using the shells allocator
> rather than Euphorias allocator.  The LPSTR type might work ok, but
> when it comes time for the functions code to poke in the values using
> the pointers for the return values (the two last ones i assume) it
> causes an exception because the pointers are not allocated correctly.
> 
Al,

Thanks for the tip.  I didn't even think about using the shell memory functions.
 I reworked the routine to use shell memory functions but am still getting the
same machine exception on the function call.  Here's the entire routine along
with the documentation from the original C source.  This is the ONLY
documentation for this function!

As you can see below, I've commented out the peek of the values from the
allocated memory so I know the problem is on the c_func().

--*******************************************************************/
--                                                                  */
-- API:                                                             */
--   cwbUN_DisplayCommandPrompter                                   */
--                                                                  */
-- Purpose:                                                         */
--   Display a prompter for a given command string similar to the   */
--   prompting done by the AS/400 command line.  The command string */
--   may be a command name, a full command string, or a partial     */
--   command name such as crt*.  Any errors encountered during      */
--   prompting will be handled by the API.  The prompter requires   */
--   the AS/400 to be at release V4R4M0 or above.                   */
--                                                                  */
--                                                                  */
-- Parameters:                                                      */
--  cwbCO_SysHandle systemHandle - input                            */
--     Handle to a system object.                                   */
--                                                                  */
--  UINT promptFlags - input                                        */
--     An integer value which specifies the prompting options for   */
--     the prompter.  Multiple values may be OR'd together:         */
--                                                                  */
--        CWBUN_PROMPT_INTERACTIVE - Also prompt interactive        */
--                                 commands.                        */
--        CWBUN_PROMPT_NO_PROGRAMS - Prompt override and change     */
--                                 exit programs for the command    */
--                                 should not be called.            */
--                                                                  */
--  LPSTR commandString - input / output                            */
--     A pointer to a string which contains the command string      */
--     to prompt.  This string may be a command name, partial       */
--     command string, or a partial commandn ame such as crt*.      */
--     After the API, this parameter will contain the resulting     */
--     command string.  This command string returned will be the    */
--     input command string if the user canceled the dialog or an   */
--     error occurred.                                              */
--                                                                  */
--  UINT * dateFormat - output                                      */
--     Returns the date format used when prompting the command.     */
--     Possible values are:                                         */
--                                                                  */
--        CWBUN_PROMPT_YEARMONTHDAY - The date format used was      */
--                                  year, month, and day.           */
--        CWBUN_PROMPT_MONTHDAYYEAR - The date format used was      */
--                                  month, day, and year.           */
--        CWBUN_PROMPT_DAYMONTHYEAR - The date format used was day, */
--                                  month, and year.                */
--        CWBUN_PROMPT_JULIAN       - The date format used was      */
--                                  Julian.                         */
--        CWBUN_PROMPT_NODATES      - A date format was not used    */
--                                  due to no date parameters       */
--                                  specified in the command.       */
--                                                                  */
--  BOOL * batchCommand - output                                    */
--     Returns whether the command which was prompted can be        */
--     executed in batch.                                           */
--                                                                  */
-- Return Codes:                                                    */
--   The following list shows common return values.                 */
--                                                                  */
--   CWB_OK - Successful completion.                                */
--       CWBUN_GETVM_FAILED - Failed to obtain Java VM.                        
*/
--   CWBUN_PROMPT_CANCEL - The user dismissed the dialog by         */
--                       pressing the cancel button.                */
--   CWBUN_PROMPT_ERROR - The dialog was dismissed due to an error  */
--                       while prompting.                           */
--   CWBUN_MISSING_PTF - The system does not have the required V4R4 */
--                       or V4R5 PTF to use the prompter.           */
--                                                                  */
-- Usage Notes:                                                     */
--                                                                  */
--   The commandString parameter must always be large enough to     */
--   hold the resulting command string.  This means the buffer      */
--   should be at least 32KB.                                       */
--                                                                  */
--   An example of the usage would be as follows:                   */
--                                                                  */
--      char commandString[32768];                                  */
--      strcpy(commandString, "crtusrprf");                         */
--                                                                  */
--      -- Prompt on crtusrprf.  Turn off prompt override call.     */
--      int rc = cwbUN_DisplayCommandPrompter(systemHandle,         */
--                                        CWBUN_PROMPT_NO_PROGRAMS, */
--                                        commandString,            */
--                                        NULL);                    */
--                                                                  */
--      -- If success, return the new command string.               */
--      if(rc == CWB_OK)                                            */
--         return commandString;                                    */
--                                                                  */
--*******************************************************************/
--CWBAPI unsigned int WINAPI cwbUN_DisplayCommandPrompter(
--                              cwbCO_SysHandle systemHandle,
--                              UINT promptFlags,
--                              LPSTR commandString,
--                              UINT * dateFormat,
--                              BOOL * batchCommand);
global constant xSHAlloc = registerw32Function( shell32, "SHAlloc", 
                {C_UINT}, C_POINTER )
global constant xSHFree = registerw32Procedure( shell32, "SHFree", 
                {C_POINTER})                
global atom xcwbUN_DisplayCommandPrompter
xcwbUN_DisplayCommandPrompter = define_c_func(cwbunapi,
    "_cwbUN_DisplayCommandPrompter@20",
            {C_UINT, C_UINT, C_POINTER, C_POINTER, C_POINTER},C_UINT)
global function cwbUN_DisplayCommandPrompter(atom system_handle, atom prompt,
                        sequence command)
    atom xcommand, xdate_format, date_format, xbatch, batch
    command &= #00
    xcommand = w32Func(xSHAlloc,{32768})
    if xcommand then
        poke(xcommand,command)
    end if
    xdate_format = w32Func(xSHAlloc,{4})
    xbatch = w32Func(xSHAlloc,{4})
    cwbUN_EURtnCode = c_func(xcwbUN_DisplayCommandPrompter,
                {system_handle, prompt, xcommand,
                xdate_format, xbatch})
--  if cwbUN_EURtnCode = CWB_OK then
--      command = peek_string(xcommand)
--      date_format = peek4u(xdate_format)
--      batch = peek4u(xbatch)
--  else
--      date_format = 0
--      batch = 0
--  end if
    w32Proc(xSHFree,{xcommand})
    w32Proc(xSHFree,{xdate_format})
    w32Proc(xSHFree,{xbatch})   

    return {cwbUN_EURtnCode, command, date_format, batch}

end function


Jonas Temple
http://www.yhti.net/~jktemple

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu