[Prev][Next][Index][Thread]

RE: Dynamically loading DLL's




> -----Original Message-----
> From: Shawn [mailto:shawn@anarchy-arts.com]
> Sent: Friday, 15 December 2000 03:45
> To: info-dylan@ai.mit.edu
> 
>     How does one find information on loading DLL's compiled with other
> languages and using them from the Dylan IDE ? 

Do you mean the Functional Developer IDE? Do you want to load the DLL
as COM server or as plain library? If as library, do you want to have
it linked to your executable, or load it dynamically?

How to use a DLL as COM server in Functional Developer is explained
in the documentation available from the Functional Objects Web Site.

If you want to link a DLL to your executable, you need the Microsoft
Linker package, available from the Functional Objects Web Site, and
the Microsoft Linker, contained in Visual C++.

If you want to load a DLL dynamically, you can use the Win32 API. You
need the Win32 Header package from Functional Objects, to do this.

Here is a simple example for the Dylan code which one could use to
call a function in dynamically loaded DLL:


define library call-dll
   use functional-dylan;
   use c-ffi;
   use win32-common;
   use win32-kernel;    
end library call-dll;

define module call-dll
   use functional-dylan;
   use simple-format;
   use c-ffi;
   use win32-common;
   use win32-kernel;
end module call-dll;


// declare function in dll
define c-function foo
   indirect: #t;
end;

define method main () => ()
   let modh = loadLibrary ("dll-test.dll");
   if (null-pointer? (modh))
      format-out ("can't load lib");
   else
      let funp = getProcAddress (modh, "foo");
      if (null-pointer? (funp))
         format-out ("can't find entry point");
      else
         // call function in dll
         foo (funp);
      end;
   end;
end method main;

begin
   main();
end;


The Functional Developer documentation explains how to pass arguments
and receive result values. See the section about Win32 and the C-FFI.

The complexity of such function calls and the error handling should
probably better be encapsuled into macros.

________________________________

Helmut Enck-Radana
mailto:her@paradigma-software.de



Follow-Ups: References: