[gambit-list] calling a function in dll

Marc Feeley feeley at iro.umontreal.ca
Wed Dec 26 00:30:21 EST 2007


I tried compiling the following code using the MinGW variant v4.1.2,  
and things work with no special linker options:

(define mbox
   (c-lambda ((pointer void) char-string char-string int) int  
"MessageBoxA"))

(mbox #f "Message body here" "Caption here" 0)

The steps are:

% gsc test.scm
% gsi test

Had you needed to link to special libraries (such as user32 and gdi32)  
you would do:

% gsc -ld-options "-luser32 -lgdi32" test.scm

Marc

On 25-Dec-07, at 5:19 AM, Nick wrote:

> Hi!
>
> I want to call a function ([1]) from a dynamic library under  
> Windows. At first I tried to call MessageBox from "user32.dll" and  
> failed to do it under gambit. When I tried DrScheme and it worked  
> fine. Here is the source:
> (module dr-scheme-ffi mzscheme
>
>   (require (lib "foreign.ss"))
>   (unsafe!)
>   (define user32.dll (ffi-lib #f))
>
>   (define mbox
>     (get-ffi-obj "MessageBoxA" user32.dll
>                  (_fun _pointer _string _string _int -> _int)))
>
>   (mbox #f "Message body here" "Caption here" 0)
> )
> I've searched through the whole gambit-list, but no one seems to  
> discuss the theme. What is the correct way to call an exported  
> function in a dll from gambit scheme? (Let them be at first  
> MessageBoxA and user32.dll).
>
> Thanks in advance,
> Nick.
>
> -----------------------------------------------------------
> [1]: http://msdn2.microsoft.com/en-us/library/aa915312.aspx
> //        BOOL ReadProcessMemory(
> //            HANDLE hProcess,                    //[in] Handle to  
> the process whose memory is being read.
> //            LPCVOID lpBaseAddress,              //[in] Pointer to  
> the base address in the specified process to be read.
> //            LPVOID lpBuffer,                    //[out] Pointer to  
> a buffer that receives the contents from the address space of the  
> specified process.
> //            DWORD nSize,                        //[in] Specifies  
> the requested number of bytes to read from the specified process.
> //            LPDWORD lpNumberOfBytesRead         //[out] Pointer to  
> the number of bytes transferred into the specified buffer.
> //            );
>
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list




More information about the Gambit-list mailing list