Hi,

I'm not the 'Win expert' you're looking for, but here's 2 ways to do it:

1 - package up your Haskell code as a COM component
    using GHC & access it via VBA just like you would any
    other COM component. HaskellDirect will give you a helping
    hand here.

2 - build a DLL that exports the Haskell functions you're interested
    in calling from VBA & access them as per usual using 'Declare'
    statements.

I'm guessing 2) is what you have in mind - here's what you need to do:

* Use 'foreign export' declarations to export the Haskell functions you want
  to call from the outside. For example,

  module Adder where
 
  adder :: Int -> Int -> IO Int  -- gratuitous use of IO
  adder x y = return (x+y)

  foreign export stdcall adder :: Int -> Int -> IO Int

* compile it up:

  c:\projects\sample> ghc-4.05 -c adder.hs -fglasgow-exts
  ...
  
  This will produce two files, adder.o and adder_stub.o

* compile up a DllMain() that starts up the Haskell RTS - attached
  to this msg is small .c file containing such a thing. Compile this
  up:

  c:\projects\sample> gcc -c dllMain.c

* construct the DLL:

   c:\projects\sample> ghc-4.05 --mk-dll -o adder.dll adder.o adder_stub.o
dllMain.o

* strip off excessive amounts of symbol table info:

   c:\projects\sample> strip adder.dll

* start using 'adder' from VBA - here's how I would 'Declare' it:

     Private Declare adder Lib "adder.dll" Alias "adder@8"
           (ByVal x As Long, ByVal y As Long) As Long

Since this Haskell DLL depends on a couple of the DLLs that come with GHC,
make sure that they are in scope/visible.

hth,
--sigbjorn

> -----Original Message-----
> From: Christian Lescher [mailto:[EMAIL PROTECTED]]
> Sent: Monday, August 14, 2000 12:53
> To: Julian Seward (Intl Vendor)
> Cc: [EMAIL PROTECTED]
> Subject: Re: Using Haskell code in VBA (MS Access)?
> 
> 
> Thank you for your answer. However, unfortunately up to now I'm so far
> as before (means: I still don't know how to build a DLL from Haskell
> code which can be called from VBA).
> 
> Is your Win expert back? Perhaps you have got some new information
> concerning my problem?
> 
> Many thanks in advance, CL
> 
> > | What is the best way to call functions implemented in Haskell from
> > | Visual Basic for Applications (MS Access)?
> > | I suppose I will have to build a DLL with GHC + Cygwin, but
> > | up to now I
> > | didn't manage to do so. I there a "How to"?
> >
> > This isn't directly what you wanted, but: I packaged up Stg Hugs
> > as a DLL which you can call from VB.  You can ask it to load
> > a Haskell module, and run functions in that module, passing
> > results back and forth to VB.
> >
> > Building DLLs with Cygwin which can be called from the native
> > MS tools seems to be somewhere between difficult and impossible,
> > depending on who you ask.  I never managed it.  A much better
> > bet is to use the Mingw32 toolchain to build DLLs -- that's how
> > I did the abovementioned experiment.
> >
> > I think GHC supports generating Mingw32-ised DLLs, so you might
> > be in luck there.  Unfortunately our Windows expert (Reuben Thomas)
> > is away until Monday, and he knows much more than I do.
> >
> > J
> 
> 
> 


begin 600 dllMain.c
M(VEN8VQU9&4@/'=I;F1O=W,N:#X-"@T*97AT97)N('9O:60@<W1A<G1U<$AA
M<VME;&PH:6YT("P@8VAA<BHJ("D[#0H-"G-T871I8R!C:&%R*B!A<F=S6UT@
M/2![(")G:&-$;&PB('T[#0H-"D)/3TP-"E-41$-!3$P-"D1L;$UA:6X-"B`@
M("@@2$%.1$Q%(&A-;V1U;&4-"B`@("P@1%=/4D0@<F5A<V]N#0H@("`L('9O
M:60J(')E<V5R=F5D#0H@("`I#0I[#0H@(&EF("AR96%S;VX@/3T@1$Q,7U!2
M3T-%4U-?051404-(*2![#0H@("`@("`O*B!">2!N;W<L('1H92!25%,@1$Q,
M('-H;W5L9"!H879E(&)E96X@:&]I<W1E9"!I;BP@8G5T('=E(&YE960@=&\@
M<W1A<G0@:70@=7`N("HO#0H@("`@("!S=&%R='5P2&%S:V5L;"@Q+"!A<F=S
M*3L-"B`@("`@(')E='5R;B!44E5%.PT*("!]#0H@(')E='5R;B!44E5%.PT*
#?0T*
`
end

Reply via email to