Re: Trouble figuring out DirectCall interface

"goobamarino" <[email protected]> Mon, 06 Oct 2003 23:53:04 -0000
Newsgroups gmane.lisp.corman
Message-ID <[email protected]>
Ok, the VC6 InProcServer project works as well. I added a call to 
WaitForSingleObject before working with the ICormanLispDirectCall and 
specified the thread handle and 3000 msec. That seems to work for me.

Relief!

--- In [email protected], "goobamarino" <goobamarino@y...> 
wrote:
> 
> Ok, the doc string is not involved, this good to know.
> 
> I'm still trying to figure out what went wrong when calling 
> CormanLispServer from an InprocServer.
> 
> Thanks for the heads up, Roger.
> 
> Wayne Rogers
> 
> 
> --- In [email protected], Roger Corman <roger@c...> wrote:
> > Wayne,
> > 
> > I am glad you got it working. One thing, though. The doc string 
> should have absolutely no effect on the generated code, and the FFI 
> certainly does not get the return type from it. Actually the 
returned 
> type is based on the lisp value returned, so you have to be 
careful. 
> It is not in the declaration.
> > 
> > If you return an integer, it returns a 32-bit signed integer. If 
> you return a float, it will return a single or double float as 
> appropriate. If you return a pointer to a foreign block, it returns 
a 
> pointer. As is typical in a language like C, you need to be careful 
> that whoever allocates a foreign block also deallocates it. You 
> shouldn't return a heap block from corman lisp that is allocated 
with 
> ct:malloc, because that has a hook that causes it to get freed when 
> the pointer object gets garbage collected. If you need to allocate 
a 
> block and return it, there are many OS calls or C language calls 
that 
> can be used directly, as long as you are sure to free them in your 
> non-lisp code afterward.
> > 
> > There is code in sys/context-menu.lisp that uses the direct call 
> interface, and from which you can get some examples. They also 
don't 
> have doc strings. Whatever caused the system to start working for 
> you, it must have been something other than the doc string.
> > 
> > Roger
> > 
> > At 07:32 PM 10/2/2003, you wrote:
> > >Problem solved.
> > >
> > >I started out creating an ATL project in VC6. I remembered from 
> > >somewhere that it had to be done in VC7 so I switch to that (a 
> free 
> > >download with the Microsoft .Net Framework SDK).
> > >
> > >I made a copy of the clbootapp project and loaded it into VC7. I 
> > >added code to create an instance of the ICormanLispDirectCall 
and 
> did 
> > >the Bless, Initialize, etc. The GetFunctionAddress call succeeds 
> but 
> > >I was getting a null function pointer to my lisp function. I 
> figured 
> > >out the lisp function and package names are case sensitive. 
> > >Presumably the exported function will always be upper case 
because 
> > >that's how they appear when the lisp evaluation prints it. The 
> > >package name looks the same way that I specified it in the lisp 
> > >environment.
> > >
> > >The last piece of the puzzle was that the return type has to be 
> > >specified like a documentation string, which I guessed based 
upon 
> an 
> > >example shown in the user guide for the defun-callback function.
> > >
> > >So my working sample now looks like this:
> > >
> > >;; lisp 
> > >(in-package "math1")
> > >
> > >(ct:defun-direct-callback add2numbers ((a win32:long)(b 
> win32:long))
> > >    "long __stdcall add(long a, long b)"
> > >     (+ a b))
> > >
> > >(export '(add2numbers))
> > >
> > >(save-image "math.img")
> > >
> > >
> > >// C++
> > >typedef long (__stdcall *pfAdd)(long a, long b);
> > >pfAdd adder;
> > >
> > >HRESULT hr = m_iLispCall->GetFunctionAddress
> (L"ADD2NUMBERS",L"math1",
> > >(LPVOID*)&adder);
> > >
> > >long sum = adder(13, 12);
> > >
> > >
> > >I hope this may help someone later on down the road.
> > >
> > >Thanks to Chris and Roger for your patience,
> > >Wayne Rogers
> > >
> > >
> > >P.S. does the new version of CCL have an updated manual?
> > >
> > >--- In [email protected], "goobamarino" 
> <goobamarino@y...> 
> > >wrote:
> > >> The m_iLispCall is an instance of ICormanLispDirectCall. When 
I 
> > >> debug in VC it shows the stack trace going into the CormanLisp 
> > >> server.
> > >> 
> > >> Do I need to do anything besides the following?:
> > >>    ;; lisp
> > >>    ct:defun-direct-callback
> > >>    save-image
> > >>    // C++
> > >>    create direct call object
> > >>    GetFunctionAddress
> > >> 
> > >> I'm not claiming anything wrong with CormanLisp, I'm just 
trying 
> to 
> > >> figure out where I'm going wrong.
> > >> 
> > >> TIA,
> > >> Wayne Rogers
> > >> 
> > >> P.S. I can post all the VC code if it may help diagnosis.
> > >> 
> > >> --- In [email protected], "Chris Double" 
> > >> <chris.double@d...> wrote:
> > >> > On Wed, 01 Oct 2003 02:49:40 -0000, "goobamarino" 
> > >> <goobamarino@y...>
> > >> > said:
> > >> > > > >                HRESULT hr = m_iLispCall-
> >GetFunctionAddress
> > >> > > > >(L"ADD2NUMBERS",L"WIN32",(LPVOID*)&m_pfAdder);
> > >> > 
> > >> > What is the value of m_iLispCall here? Is that pointer 
valid? 
> Are 
> > >> you
> > >> > sure it's inside GetFunctionAddress that is crashing or 
could 
> it 
> > >> be an
> > >> > invalid m_iLispCall causing GetFunctionAddress to do things 
> > >inside 
> > >> of an
> > >> > invalid object?
> > >> > 
> > >> > Chris.
> > >> > -- 
> > >> >   Chris Double
> > >> >   chris.double@d...
> > >
> > >
> > >
> > >To unsubscribe from this group, send an email to:
> > >[email protected]
> > >
> > > 
> > >
> > >Your use of Yahoo! Groups is subject to 
> http://docs.yahoo.com/info/terms/


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/SyjtlB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/