MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Can you call 32 Bit DLLs from Mathematica

  • To: mathgroup at
  • Subject: [mg125272] Re: Can you call 32 Bit DLLs from Mathematica
  • From: Todd Gayley <tgayley at>
  • Date: Sat, 3 Mar 2012 06:55:21 -0500 (EST)
  • Delivered-to:
  • References: <jinjsa$d4v$>

At 06:48 AM 3/2/2012, Oleksandr Rasputinov wrote:
>On Thu, 01 Mar 2012 10:43:22 -0000, Guido <guido.reichert at> wrote:
> > I am using a System Dynamics software (Vensim DSS) that is still a 32
> > Bit application and provides a full 32 Bit DLL for use with other
> > programs. I had thought that I can call that DLL from Mathematica 8.0.
> >
> > Such a call produces a 'BadFormat' error and the Vensim support says
> > that 64 Bit and 32 Bit do not mix well. Is there any chance to call a
> > 32 Bit DLL from Mathematica 8.0?
> >
> > Kind regards
> >
> > Guido
> >
>Not from the 64-bit version, no; it is simply not possible for a 64-bit
>Windows process to load a 32-bit DLL directly. Fortunately, both 32- and
>64-bit versions of Mathematica are provided in the standard installation,
>probably for exactly this reason. To help you start the 32-bit Mathematica
>kernel on a 64-bit system, you can evaluate:
>    EvaluatorNames -> Append[
>      EvaluatorNames /. Options[$FrontEnd],
>      "Local (32-bit)" -> {
>        "AutoStartOnLaunch" -> False,
>        "Executable" -> FileNameJoin[{
>          $InstallationDirectory, "SystemFiles",
>          "Kernel", "Binaries", "Windows", "MathKernel.exe"
>        }]
>      }
>    ]
>which adds an entry for the 32-bit kernel in the kernel configuration
>options dialog, i.e. the one produced by evaluating:
>With this set up, you just need to select the menu option Evaluation |
>Notebook's Kernel | Local (32-bit) in a new notebook (before evaluating
>anything) in order to have that notebook use the 32-bit kernel. This can
>also be accomplished programmatically by evaluating:
>SetOptions[EvaluationNotebook[], Evaluator -> "Local (32-bit)"]

That's a great tip, and I have never seen that described, but I don't 
think it will solve the original poster's problem. It's the bitness 
of the .NET/Link process, not Mathematica, that needs to match the 
DLL he is calling. Even if he runs a 32-bit Mathematica kernel, when 
.NET/Link is launched it will be a native 64-bit .NET process because 
the operating system is 64-bit Windows.

The way to handle the problem is to force .NET/Link to run in 32-bit mode:

     ReinstallNET["Force32Bit" -> True]

Todd Gayley
Wolfram Research

  • Prev by Date: Re: Automatic Numbering in Mathematica
  • Next by Date: Re: Can I solve this system of nonlinear equations?
  • Previous by thread: Re: irritating screen jumps in Mathematica 8.0.4
  • Next by thread: Suppress Cell Labels