1. An old C function problem revisited

All,

I asked a question about this C function call a couple of years ago and got some
answers but never could resolve the problem.  Every time I call the following
routine:

--CWBAPI unsigned int WINAPI cwbUN_DisplayCommandPrompter(
--                              cwbCO_SysHandle systemHandle,
--                              UINT promptFlags,
--                              LPSTR commandString,
--                              UINT * dateFormat,
--                              BOOL * batchCommand);

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, xprompt, xdate_format, date_format, xbatch, batch
    xcommand = allocate(32768)
    mem_set(xcommand, ' ', 32768)
    poke(xcommand, command)
    poke(xcommand + length(command), #00)
    xdate_format = allocate(4)
    xbatch = allocate(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
    free(xcommand)
    free(xdate_format)
    free(xbatch)

    return {cwbUN_EURtnCode, command, date_format, batch}

end function


I get the following error:

c:\eutools\include\cwbun.ew:3631 in function cwbUN_DisplayCommandPrompter()
A machine-level exception occurred during execution of this statement

I have played around with this one for a week or so and am ready to give up
again.  You might be asking why 32768 is allocated but this routine can return a
much longer string than what is provided so you have to allocate enough.

Thanks for any help!

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

new topic     » topic index » view message » categorize

2. Re: An old C function problem revisited

Jonas Temple wrote:
> 
> All,
> 
> I asked a question about this C function call a couple of years ago and got
> some answers but never could resolve the problem.  Every time I call the
> following
> routine:
> 
> }}}
<eucode>
> --CWBAPI unsigned int WINAPI cwbUN_DisplayCommandPrompter(
> --                              cwbCO_SysHandle systemHandle,
> --                              UINT promptFlags,
> --                              LPSTR commandString,
> --                              UINT * dateFormat,
> --                              BOOL * batchCommand);
> 
> 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, xprompt, xdate_format, date_format, xbatch, batch
>     xcommand = allocate(32768)
>     mem_set(xcommand, ' ', 32768)
>     poke(xcommand, command)
>     poke(xcommand + length(command), #00)
>     xdate_format = allocate(4)
>     xbatch = allocate(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
>     free(xcommand)
>     free(xdate_format)
>     free(xbatch)
> 
>     return {cwbUN_EURtnCode, command, date_format, batch}
> 
> end function
> 
> </eucode>
{{{

> 
> I get the following error:
> 
> c:\eutools\include\cwbun.ew:3631 in function cwbUN_DisplayCommandPrompter()
> A machine-level exception occurred during execution of this statement
> 
> I have played around with this one for a week or so and am ready to give up
> again.  You might be asking why 32768 is allocated but this routine can return
> a much longer string than what is provided so you have to allocate enough.
> 
> Thanks for any help!
> 
> Jonas Temple
> <a href="http://www.yhti.net/~jktemple">http://www.yhti.net/~jktemple</a>


Hi there,



Which line in the code does :3631 refer to... is it:

cwbUN_EURtnCode = c_func(xcwbUN_DisplayCommandPrompter,
                {system_handle, prompt, xcommand,
                xdate_format, xbatch})

or some other line?



Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

new topic     » goto parent     » topic index » view message » categorize

3. Re: An old C function problem revisited

Al Getz wrote:
> Hi there,
> 
> 
> Which line in the code does :3631 refer to... is it:
> 
> cwbUN_EURtnCode = c_func(xcwbUN_DisplayCommandPrompter,
>                 {system_handle, prompt, xcommand,
>                 xdate_format, xbatch})
> 

It's the c_func() call.  The problem is I don't know which parms is causing the
problem and I've double and triple checked the parms.

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

new topic     » goto parent     » topic index » view message » categorize

4. Re: An old C function problem revisited

Jonas Temple wrote:
> 
> All,
> 
> I asked a question about this C function call a couple of years ago and got
> some answers but never could resolve the problem.  Every time I call the
> following
> routine:
> 
> }}}
<eucode>
> --CWBAPI unsigned int WINAPI cwbUN_DisplayCommandPrompter(
> --                              cwbCO_SysHandle systemHandle,
> --                              UINT promptFlags,
> --                              LPSTR commandString,
> --                              UINT * dateFormat,
> --                              BOOL * batchCommand);
> 
> 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, xprompt, xdate_format, date_format, xbatch, batch
>     xcommand = allocate(32768)
>     mem_set(xcommand, ' ', 32768)
>     poke(xcommand, command)
>     poke(xcommand + length(command), #00)
>     xdate_format = allocate(4)
>     xbatch = allocate(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
>     free(xcommand)
>     free(xdate_format)
>     free(xbatch)
> 
>     return {cwbUN_EURtnCode, command, date_format, batch}
> 
> end function
> 
> </eucode>
{{{

> 
> I get the following error:
> 
> c:\eutools\include\cwbun.ew:3631 in function cwbUN_DisplayCommandPrompter()
> A machine-level exception occurred during execution of this statement
> 
> I have played around with this one for a week or so and am ready to give up
> again.  You might be asking why 32768 is allocated but this routine can return
> a much longer string than what is provided so you have to allocate enough.
> 
> Thanks for any help!
> 
> Jonas Temple
> <a href="http://www.yhti.net/~jktemple">http://www.yhti.net/~jktemple</a>

Jonas: 
   It may be because you are not using the correct function name.
   You may have to use 'A' at the end of function name
   if you are using ANSI. Take a look at this link it says
   something about not having and 'A' or 'W' the function
   will be OEM call.
   I don't know much about AS400, I hope this helps.
   

http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/rzaik/rzaikcaexpressprogstd.htm#HDRCAEXPRESSPROGSTD

Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

5. Re: An old C function problem revisited

Bernie Ryan wrote:
> 
> Jonas: 
>    It may be because you are not using the correct function name.
>    You may have to use 'A' at the end of function name
>    if you are using ANSI. Take a look at this link it says
>    something about not having and 'A' or 'W' the function
>    will be OEM call.
>    I don't know much about AS400, I hope this helps.
>    
> 
> <a
> href="http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/rzaik/rzaikcaexpressprogstd.htm#HDRCAEXPRESSPROGSTD">http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/rzaik/rzaikcaexpressprogstd.htm#HDRCAEXPRESSPROGSTD</a>
> 
> Bernie

Bernie,

Nice research!  Unfortunately there's no 'A' version of this routine.  :(

new topic     » goto parent     » topic index » view message » categorize

6. Re: An old C function problem revisited

Jonas Temple wrote:
> 
> Al Getz wrote:
> > Hi there,
> > 
> > 
> > Which line in the code does :3631 refer to... is it:
> > 
> > cwbUN_EURtnCode = c_func(xcwbUN_DisplayCommandPrompter,
> >                 {system_handle, prompt, xcommand,
> >                 xdate_format, xbatch})
> > 
> 
> It's the c_func() call.  The problem is I don't know which parms is causing
> the problem and I've double and triple checked the parms.
> 
> Jonas Temple
> <a href="http://www.yhti.net/~jktemple">http://www.yhti.net/~jktemple</a>

Make sure you are not getting zero back for the define_c_func call.

xcwbUN_DisplayCommandPrompter = define_c_func(cwbunapi,
"_cwbUN_DisplayCommandPrompter@20", {C_UINT, C_UINT, C_POINTER, C_POINTER,
C_POINTER},C_UINT)
if xcwbUN_DisplayCommandPrompter = 0 then
    puts(2, "Couldn't get function handle!\n") -- or message box
end if


Check the DLL with a tool that lists DLL contents and make sure the name is
right -- I've used DLL Export Viewer from http://www.nirsoft.net. (Win9x used to
have Quickview that did this -- I wish XP did!)

--
"Any programming problem can be solved by adding a level of indirection."
--anonymous
"Any performance problem can be solved by removing a level of indirection."
--M. Haertel
"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare
j.

new topic     » goto parent     » topic index » view message » categorize

7. Re: An old C function problem revisited

Jason Gade wrote:
> 
> Jonas Temple wrote:
> > 
> > Al Getz wrote:
> > > Hi there,
> > > 
> > > 
> > > Which line in the code does :3631 refer to... is it:
> > > 
> > > cwbUN_EURtnCode = c_func(xcwbUN_DisplayCommandPrompter,
> > >                 {system_handle, prompt, xcommand,
> > >                 xdate_format, xbatch})
> > > 
> > 
> > It's the c_func() call.  The problem is I don't know which parms is causing
> > the problem and I've double and triple checked the parms.
> > 
> > Jonas Temple
> > <a href="http://www.yhti.net/~jktemple">http://www.yhti.net/~jktemple</a>
> 
> Make sure you are not getting zero back for the define_c_func call.
> 
> }}}
<eucode>xcwbUN_DisplayCommandPrompter = define_c_func(cwbunapi,
> "_cwbUN_DisplayCommandPrompter@20", {C_UINT,
> C_UINT, C_POINTER, C_POINTER, C_POINTER},C_UINT)
> if xcwbUN_DisplayCommandPrompter = -1 then
>     puts(2, "Couldn't get function handle!\n") -- or message box
> end if</eucode>
{{{

> 
> Check the DLL with a tool that lists DLL contents and make sure the name is
> right -- I've
> used DLL Export Viewer from <a
> href="http://www.nirsoft.net">http://www.nirsoft.net</a>.
> (Win9x used to have Quickview that did this -- I wish XP did!)

Sorry, check for -1, not 0.

--
"Any programming problem can be solved by adding a level of indirection."
--anonymous
"Any performance problem can be solved by removing a level of indirection."
--M. Haertel
"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare
j.

new topic     » goto parent     » topic index » view message » categorize

8. Re: An old C function problem revisited

I guess I really failed to mention that the prompt dialog IS presented when the
function is called.  The dialog works normally and the "CRTPGM" string I pass in
is received as well.

The problem happens when I click "Okay" or "Cancel" on the dialog.  The other
thing I faile to mention is the dialog that is displayed is a Java app.  Mabye
that has something to do with it?  Mabye not because this routine is supposed to
be a C/C++ interface to the Java app.  I also know this dialog works as it's
called from other apps provided by the vendor.

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

new topic     » goto parent     » topic index » view message » categorize

9. Re: An old C function problem revisited

Jonas Temple wrote:
> 
> I guess I really failed to mention that the prompt dialog IS presented when
> the function is called.  The dialog works normally and the "CRTPGM" string I
> pass in is received as well.  
> 
> The problem happens when I click "Okay" or "Cancel" on the dialog.  The other
> thing I faile to mention is the dialog that is displayed is a Java app.  Mabye
> that has something to do with it?  Mabye not because this routine is supposed
> to be a C/C++ interface to the Java app.  I also know this dialog works as
> it's
> called from other apps provided by the vendor.

Sounds like a calling convention mixup to me.  Have you tried using cdecl?

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

10. Re: An old C function problem revisited

Jonas Temple wrote:
> 
> I guess I really failed to mention that the prompt dialog IS presented when
> the function is called.  The dialog works normally and the "CRTPGM" string I
> pass in is received as well.  
> 
> The problem happens when I click "Okay" or "Cancel" on the dialog.  The other
> thing I faile to mention is the dialog that is displayed is a Java app.  Mabye
> that has something to do with it?  Mabye not because this routine is supposed
> to be a C/C++ interface to the Java app.  I also know this dialog works as
> it's
> called from other apps provided by the vendor.
> 
> Jonas Temple
> <a href="http://www.yhti.net/~jktemple">http://www.yhti.net/~jktemple</a>

Sorry, it was the only suggestion I had. The fact that it crashes when you try
to dismiss it is useful, though. If it crashes when it returns, there must be
something happening to the stack I think.

What is the macro CWBAPI defined as? 

--
"Any programming problem can be solved by adding a level of indirection."
--anonymous
"Any performance problem can be solved by removing a level of indirection."
--M. Haertel
"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare
j.

new topic     » goto parent     » topic index » view message » categorize

11. Re: An old C function problem revisited

Matt Lewis wrote:
> 
> Sounds like a calling convention mixup to me.  Have you tried using cdecl?
> 
That's what I'm suspicious of.  Can you explain the "cdecl" thing?  I'm not
familiar with that.

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

new topic     » goto parent     » topic index » view message » categorize

12. Re: An old C function problem revisited

Jonas Temple wrote:
> 
> Matt Lewis wrote:
> > 
> > Sounds like a calling convention mixup to me.  Have you tried using cdecl?
> > 
> That's what I'm suspicious of.  Can you explain the "cdecl" thing?  I'm not
> familiar with that.
> 
> Jonas Temple
> <a href="http://www.yhti.net/~jktemple">http://www.yhti.net/~jktemple</a>

I thought that cdecl mainly affected translated apps... plus your C prototype
shows WINAPI which would mean that it is stdcall, right?

--CWBAPI unsigned int WINAPI cwbUN_DisplayCommandPrompter(
--                              cwbCO_SysHandle systemHandle,
--                              UINT promptFlags,
--                              LPSTR commandString,
--                              UINT * dateFormat,
--                              BOOL * batchCommand);

The difference is how the stack gets cleaned up. Euphoria, and most Windows
routines, use stdcall. With stdcall, the called function cleans up the stack.
With cdecl, the calling function cleans up the stack.

To use cdecl, make your define_c_func like this:
xcwbUN_DisplayCommandPrompter = define_c_func(cwbunapi,
"+_cwbUN_DisplayCommandPrompter@20", {C_UINT, C_UINT, C_POINTER, C_POINTER,
C_POINTER},C_UINT)


Note the "+" leading on the function name. But I still think you shouldn't need
it.

Look for the #define CWBAPI and find out what that means.

--
"Any programming problem can be solved by adding a level of indirection."
--anonymous
"Any performance problem can be solved by removing a level of indirection."
--M. Haertel
"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare
j.

new topic     » goto parent     » topic index » view message » categorize

13. Re: An old C function problem revisited

Jason Gade wrote:
> 
> To use cdecl, make your define_c_func like this:
> }}}
<eucode>xcwbUN_DisplayCommandPrompter = define_c_func(cwbunapi,
> "+_cwbUN_DisplayCommandPrompter@20",
> {C_UINT, C_UINT, C_POINTER, C_POINTER, C_POINTER},C_UINT)</eucode>
{{{

> 
> Note the "+" leading on the function name. But I still think you shouldn't
> need
> it.

There's no function that starts with a "+" exported from the dll.

> 
> Look for the #define CWBAPI and find out what that means.
> 

 From looking through the C include files I believe it's defined as:

__declspec( dllimport ) 
or
__declspec( dllexport )

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

new topic     » goto parent     » topic index » view message » categorize

14. Re: An old C function problem revisited

Jonas Temple wrote:
> 
> Jason Gade wrote:
> >
> > Note the "+" leading on the function name. But I still think you shouldn't
> > need
> > it.
> 
> There's no function that starts with a "+" exported from the dll.

Correct, but if you look at the documentation for declare_c_proc...

"On Windows, you can add a '+' character as a prefix to the function name. This
tells Euphoria that the function uses the cdecl calling convention. By default,
Euphoria assumes that C routines accept the stdcall convention."


The Euphoria Standard Library project :
    http://esl.sourceforge.net/
The Euphoria Standard Library mailing list :
    https://lists.sourceforge.net/lists/listinfo/esl-discussion

new topic     » goto parent     » topic index » view message » categorize

15. Re: An old C function problem revisited

D. Newhall wrote:
> 
> Correct, but if you look at the documentation for declare_c_proc...
> 
> "On Windows, you can add a '+' character as a prefix to the function name.
> This
> tells Euphoria that the function uses the cdecl calling convention. By
> default,
> Euphoria assumes that C routines accept the stdcall convention."
> 
> 
Good call.  I added the '+' to the front of two functions that I used that are
defined with CWBAPI.  I still got the same error.  Just a glimmer of hope there
for a moment.  :)

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

new topic     » goto parent     » topic index » view message » categorize

16. Re: An old C function problem revisited

Jonas Temple wrote:
> 
> Jason Gade wrote:
> > 
> > To use cdecl, make your define_c_func like this:
> > }}}
<eucode>xcwbUN_DisplayCommandPrompter = define_c_func(cwbunapi,
> > "+_cwbUN_DisplayCommandPrompter@20",
> > {C_UINT, C_UINT, C_POINTER, C_POINTER, C_POINTER},C_UINT)</eucode>
{{{

> > 
> > Note the "+" leading on the function name. But I still think you shouldn't
> > need
> > it.
> 
> There's no function that starts with a "+" exported from the dll.
> 
> > 
> > Look for the #define CWBAPI and find out what that means.
> > 
> 
>  From looking through the C include files I believe it's defined as:
> 
> __declspec( dllimport ) 
> or
> __declspec( dllexport )
> 
> Jonas Temple
> <a href="http://www.yhti.net/~jktemple">http://www.yhti.net/~jktemple</a>

I think I'm all out of suggestions! I'm not sure about the __declspec bit, I've
seen it but I don't really understand it. It might be telling the linker that
this is a dll routine rather than one that is statically linked.

I still think that it has something to do with the return value and stack
cleanup.

I found your old thread here:
http://www.listfilter.com/cgi-bin/esearch.exu?thread=1&fromMonth=5&fromYear=8&toMonth=7&toYear=8&keywords=%22[OT]+-+Help+with+routine+name+in+.dll%22

--
"Any programming problem can be solved by adding a level of indirection."
--anonymous
"Any performance problem can be solved by removing a level of indirection."
--M. Haertel
"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare
j.

new topic     » goto parent     » topic index » view message » categorize

17. Re: An old C function problem revisited

Jason Gade wrote:
> 
> I think I'm all out of suggestions! I'm not sure about the __declspec bit,
> I've
> seen it but I don't really understand it. It might be telling the linker that
> this is a dll routine rather than one that is statically linked.
> 
Here's something in the MS documentation about __declspec:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/msmod_17.asp

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

new topic     » goto parent     » topic index » view message » categorize

18. Re: An old C function problem revisited

Jonas:
   Another suggestion:

   comment out each of the following lines one at a time
   and see if anyone being commented out stops the crashing.


      command = peek_string(xcommand)
      date_format = peek4u(xdate_format)
      batch = peek4u(xbatch)

   if peek_string is causing the crash then try just peeking 10 bytes
   or so because it may not be null terminated.

Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

19. Re: An old C function problem revisited

Bernie Ryan wrote:
>    comment out each of the following lines one at a time
>    and see if anyone being commented out stops the crashing.
> 
> 
>       command = peek_string(xcommand)
>       date_format = peek4u(xdate_format)
>       batch = peek4u(xbatch)
> 
>    if peek_string is causing the crash then try just peeking 10 bytes
>    or so because it may not be null terminated.
> 
Bernie,

Thanks for the suggestion but in this case the machine exception occurs during
the c_func() call.

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

new topic     » goto parent     » topic index » view message » categorize

20. Re: An old C function problem revisited

Jonas Temple wrote:
> 
> All,
> 
> I asked a question about this C function call a couple of years ago and got
> some answers but never could resolve the problem.  Every time I call the
> following
> routine:
> 
> }}}
<eucode>
> --CWBAPI unsigned int WINAPI cwbUN_DisplayCommandPrompter(
> --                              cwbCO_SysHandle systemHandle,
> --                              UINT promptFlags,
> --                              LPSTR commandString,
> --                              UINT * dateFormat,
> --                              BOOL * batchCommand);
> 
> 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, xprompt, xdate_format, date_format, xbatch, batch
>     xcommand = allocate(32768)
>     mem_set(xcommand, ' ', 32768)
>     poke(xcommand, command)
>     poke(xcommand + length(command), #00)
>     xdate_format = allocate(4)
>     xbatch = allocate(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
>     free(xcommand)
>     free(xdate_format)
>     free(xbatch)
> 
>     return {cwbUN_EURtnCode, command, date_format, batch}
> 
> end function
> 
> </eucode>
{{{

> 
> I get the following error:
> 
> c:\eutools\include\cwbun.ew:3631 in function cwbUN_DisplayCommandPrompter()
> A machine-level exception occurred during execution of this statement
> 
> I have played around with this one for a week or so and am ready to give up
> again.  You might be asking why 32768 is allocated but this routine can return
> a much longer string than what is provided so you have to allocate enough.
> 
> Thanks for any help!
> 
> Jonas Temple
> <a href="http://www.yhti.net/~jktemple">http://www.yhti.net/~jktemple</a>


Hello there,


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.

Again, if you can post or link to the doc's it would help i think.


Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

new topic     » goto parent     » topic index » view message » categorize

21. Re: An old C function problem revisited

I thought you said that a Dialog was appearing when you used this
function then I would suggest that you try commenting out
because functions happen quickly and it sometimes difficult to
tell exactly when it is failing.

Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

22. Re: An old C function problem revisited

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 message » categorize

23. Re: An old C function problem revisited

Jonas Temple wrote:
> 
> 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().
> 
> }}}
<eucode>
> --*******************************************************************/
> --                                                                  */
> -- 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,
<snip>

Hi Jonas,


Oh ok, well sorry that didnt work so i guess we are grasping at
straws now...

I noticed a difference in params between the def of 
cwbUN_DisplayCommandPrompter
and the example they quote in the 'docs'.
What's up with that?
Also, they null the two pointers out before they pass them (i guess)
so you could try that.
Also, did you try allocating more bytes then needed for the string?
Are you sure the systemhandle you are passing is valid?
Did you try leaving off the "@20" at the end of the function name?
and possibly leave off the "_" in front of the function name?
Ask Rob if "poke" works correctly for memory allocated with the
shells allocator...perhaps try writing then reading with 'peek'.

Just some possibilities, which i cant say for sure if they will help
or not.  When this kind of thing happens to me and i dont have a solid
answer i usually try a bunch of different things...whatever i can think
of...to see if i can stumble on the correct answer.  Usually sooner or
later something comes up that solves it.  Is there anyone associated
with the dll you are using you can ask?  Is there a web site for this
'library' ?  Whenever i had a problem like this in the past it was
one of the things you already covered:
*incorrect numb of params
*param wrong type
*param not passed properly as required by Eu
*not enough string space allocated
There was one problem where the memory had to be allocated in the same
process as the SystemListView i was trying to access.  Nothing else
helped either (SHMalloc, COM's IMalloc interface)...had to allocate
space in the same process of the ListView and geeze that was a pain,
but it finally worked.  It would be hard to believe that would be
necessary here however because (i assume) the dll is mapped into your
programs address space right?  So any functions you call should be
able to find your pointers right?

BTW, WINAPI is usually declared as std except i think in Mac where
it might be cdecl.



Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu