Re: An old C function problem revisited

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

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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu