Re: Problems with FFI
"goobamarino" <[email protected]> Mon, 07 Apr 2003 12:16:03 -0000
| Newsgroups | gmane.lisp.corman |
|---|---|
| Message-ID | <[email protected]> |
--- In [email protected], Chris Double <chris.double@d...> wrote: > I don't have Corman Lisp handy to run so the following comments are untested, > but I'm pretty sure their right. > > > } OPENFILENAME, *LPOPENFILENAME; > > There are two types defined here. One is OPENFILENAME which will have the size > of the structure. The other is LPOPENFILENAME which is a pointer type and is > only of the size of the pointer. > > > (let ((lpOFN (malloc (sizeof 'LPOPENFILENAME)))) > > Here you are mallocing a size of the pointer type. I think this should be > (sizeof 'OPENFILENAME). What do (sizeof 'OPENFILENAME) and (sizeof > 'LPOPENFILENAME) return? > > > (with-c-struct (strct lpOFN OPENFILENAME) > > You are offsetting into the memory allocated as if it was a fully allocated > OPENFILENAME, but it is only a few bytes big. You will be overwriting memory > here. Fix the malloc above it and this should be fine. > > > lpstrFile (malloc (* (sizeof 'LPTSTR) 260)) > > Here you probably mean to allocate a string of 260 characteres. (malloc 260) > would be sufficient. I believe what you are actually saying here is malloc > something 260 * the sizeof a pointer (again that LP indicates a pointer > type). So you are allocating more than needed, not really a problem. > > > nMaxFile 260 > > This indicates you really did want (malloc 260) before. > > Try those fixes and see how things go. > > Chris. You're right, I changed the (malloc (sizeof 'LPOPENFILENAME)) to (malloc (sizeof 'OPENFILENAME)) and that seems to be working just fine. And I thought I knew C!! I guess what thouroughly confuses me is the occasions when a declaration does look like (malloc (Sizeof 'somepointer)). It doesn't make sense because all pointers are 4 bytes on the Windows platform. Is this merely so that when the resulting (cref somepointer ptr 0) is called the lisp knows what to do? ------------------------ Yahoo! Groups Sponsor ---------------------~--> Get 128 Bit SSL Encryption! http://us.click.yahoo.com/W7NydA/hdqFAA/VygGAA/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/