1. RE: [OT] - Help with routine name in .dll
> From: Jonas Temple [mailto:jtemple at yhti.net]
> I'm trying to create a wrapper for a .dll and I can't seem to
> figure out the name of the routine in the .dll itself. The
> documentation says the function is cwbUN_DisplayCommandPrompter
> but I can't find that "exact" name in the .dll. Looking at the
> .lib file I find:
>
> __imp__cwbUN_DisplayCommandPrompter@20
> _cwbUN_DisplayCommandPrompter@20
Not sure what __imp_ means, but I'd try _cwbUN_DisplayCommandPrompter@20
first. That's a standard 'extern c' name decoration (add an underscore and
the sum of the bytes for all the arguments that the func takes). If that
doesn't work, try the other one.
> If I want to use define_c_func() what is the name I should use? BTW,
> the excerpt from the .lib file was copied with Context so I
> don't know what "@20" means. Maybe that's the problem?
@20 means that it takes 5 arguments (assuming 4-bytes for each).
Do you have Dependency Walker (http://www.dependencywalker.com)? It's great
for looking at a dll's exports.
Matt Lewis
2. RE: [OT] - Help with routine name in .dll
Matt/Pete,
Thanks for the help! Matt, "_cwbUN_DisplayCommandPrompter@20" was the
actual exported name. I'll definitely get Dependency Walker!
Now a follow-up question. I'm getting the command prompter as expected
but when I close the dialog I'm getting a machine error on the function
call. Is there anything in the following C declaration that might cause
this?
--CWBAPI unsigned int WINAPI cwbUN_DisplayCommandPrompter(
-- cwbCO_SysHandle systemHandle,
-- UINT promptFlags,
-- LPSTR commandString,
-- UINT * dateFormat,
-- BOOL * batchCommand);
TIA,
Jonas
Matt Lewis wrote:
> Not sure what __imp_ means, but I'd try _cwbUN_DisplayCommandPrompter@20
> first. That's a standard 'extern c' name decoration (add an underscore
> and
> the sum of the bytes for all the arguments that the func takes). If
> that
> doesn't work, try the other one.
>
> Do you have Dependency Walker (http://www.dependencywalker.com)? It's
> great
> for looking at a dll's exports.
>
> Matt Lewis
>
3. RE: [OT] - Help with routine name in .dll
> From: Jonas Temple [mailto:jtemple at yhti.net]
> Now a follow-up question. I'm getting the command prompter
> as expected but when I close the dialog I'm getting a
> machine error on the function call. Is there anything in
> the following C declaration that might cause this?
>
> --CWBAPI unsigned int WINAPI cwbUN_DisplayCommandPrompter(
> -- cwbCO_SysHandle systemHandle,
> -- UINT promptFlags,
> -- LPSTR commandString,
> -- UINT * dateFormat,
> -- BOOL * batchCommand);
My guess would be a pad parameter. Not sure what a cwbCO_SysHandle is, but
commandString, dateFormat and batchCommand are all pointers. Did you pass a
value instead of a pointer for dateFormat or batchCommand? Or, perhaps some
initialization didn't take place before calling cwbUN_DisplayCommandPrompter
(like in the creation of systemHandle?).
Matt Lewis
4. RE: [OT] - Help with routine name in .dll
Matt,
Appreciate the help! I've included the full implementation of this
function:
global atom xcwbUN_DisplayCommandPrompter
xcwbUN_DisplayCommandPrompter = define_c_func(cwbunapi,
"_cwbUN_DisplayCommandPrompter@20",
{C_ULONG, C_ULONG, C_POINTER, C_POINTER, C_POINTER},
C_ULONG)
global function cwbUN_DisplayCommandPrompter(atom system_handle, atom
prompt,
sequence command)
atom xcommand, xdate_format, date_format, xbatch, batch
xcommand = allocate(32000)
mem_set(xcommand, ' ', 32000)
poke(xcommand, command)
poke(xcommand + length(command), #00)
xdate_format = allocate(4)
poke(xdate_format, 0)
date_format = 0
xbatch = allocate(4)
poke(xbatch, 0)
batch = 0
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)
end if
free(xcommand)
free(xdate_format)
free(xbatch)
return {cwbUN_EURtnCode, command, date_format, batch}
end function
and is called as:
command = "crtrpgpgm pgm(jtemple/test)"
rtn_seq = cwbUN_DisplayCommandPrompter(system_handle,
CWBUN_PROMPT_INTERACTIVE, command)
The window appears and everything in the window works *until* I attempt
to close the window, either by clicking Okay, Cancel or the system close
box. I think the window is written in Java, though.
Does the WINAPI in the C declaration have anything to do with the
problem?
Thanks again!
Jonas
Matt Lewis wrote:
> > Now a follow-up question. I'm getting the command prompter
> > as expected but when I close the dialog I'm getting a
> > machine error on the function call. Is there anything in
> > the following C declaration that might cause this?
> >
> > --CWBAPI unsigned int WINAPI cwbUN_DisplayCommandPrompter(
> > -- cwbCO_SysHandle systemHandle,
> > -- UINT promptFlags,
> > -- LPSTR commandString,
> > -- UINT * dateFormat,
> > -- BOOL * batchCommand);
>
> My guess would be a pad parameter. Not sure what a cwbCO_SysHandle is,
> but
> commandString, dateFormat and batchCommand are all pointers. Did you
> pass a
> value instead of a pointer for dateFormat or batchCommand? Or, perhaps
> some
> initialization didn't take place before calling
> cwbUN_DisplayCommandPrompter
> (like in the creation of systemHandle?).
>
> Matt Lewis
>
5. RE: [OT] - Help with routine name in .dll
> From: Jonas Temple [mailto:jtemple at yhti.net]
<snip>
> poke(xdate_format, 0)
Maybe change this to poke4?
<snip>
> poke(xbatch, 0)
...and change this to poke4? If the command prompter uses these for
anything other than for returning values, that could be causing problems if
you have a bogus value.
<snip>
Otherwise I don't see anything obviously wrong with it.
> The window appears and everything in the window works *until*
> I attempt to close the window, either by clicking Okay,
> Cancel or the system close box. I think the window is written
> in Java, though.
It shouldn't matter that it's written in Java.
> Does the WINAPI in the C declaration have anything to do with the
> problem?
WINAPI basically means that the function is stdcall, so you should be fine
there. I assume that it never returns control to Euphoria? CWBAPI seems to
be defined as CwbExport (which seems to vanish under GNU, but I don't know
what it does under other compilers).
Matt Lewis
6. RE: [OT] - Help with routine name in .dll
Matt,
> > poke(xdate_format, 0)
>
> Maybe change this to poke4?
I changed both of the poke to poke4. Still crashes. The date_format
and batch parms are both (according to the docs) defined as output only.
> WINAPI basically means that the function is stdcall, so you should be
> fine
> there. I assume that it never returns control to Euphoria?
It actually does return control to Euphoria. I tried it with both 2.3
and 2.4. 2.4 tells me:
C:\EUTOOLS\INCLUDE\cwbun.ew:3480 in function
cwbUN_DisplayCommandPrompter()
A machine-level exception occurred during execution of this statement
but, again, only after I close the prompt window.
Weird, huh?
Jonas
7. RE: [OT] - Help with routine name in .dll
>> I changed both of the poke to poke4. Still crashes. The date_format
>> and batch parms are both (according to the docs) defined as output only.
Jonas:
If they are outputs try creating some buffers to accept each ouput data.
constant date_format = allocate(4) then pass date_format ( the address )
Bernie