Re: Trouble figuring out DirectCall interface

"goobamarino" <[email protected]> Fri, 03 Oct 2003 02:32:39 -0000
Newsgroups gmane.lisp.corman
Message-ID <[email protected]>
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...


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Upgrade to 128-Bit SSL Security!
http://us.click.yahoo.com/p7cEmB/s7qGAA/yigFAA/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/