Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The .NET/Link tutorial shows how to call functions defined in DLLs. The example uses the GetTickCount Win32 API function

<< NetLink`
getTickCount = DefineDLLFunction["GetTickCount", "kernel32.dll", "int", {}]


(* ==> 91226108 *)

Unfortunately this does not work by default when usign a 64-bit version of Mathematica to call a function defined in a 32-bit DLL. Let's use the 32-bit version of kernel32.dll to test:

getTickCount = 
 DefineDLLFunction["GetTickCount", "c:\\windows\\SysWOW64\\kernel32.dll", "int", {}]


NET::netexcptn: A .NET exception occurred: System.BadImageFormatException: 
   An attempt was made to load a program with an incorrect format. 
   (Exception from HRESULT: 0x8007000B)
   at Wolfram.NETLink.DynamicDLLNamespace.DLLWrapper15.GetTickCount().

How can I call a 32-bit DLL from a 64-bit Mathematica?

share|improve this question
I thought this will be valuable for the community. It's based on a MathGroup question I solved. – Szabolcs Mar 2 '12 at 10:13
up vote 22 down vote accepted

The solution is forcing .NET/Link to load its 32-bit executable instead of the 64-bit one. Since Mathematica communicated with the .NET/Link process through MathLink, it does not matter if the Mathematica kernel is 64 bit and the .NET/Link executable is a 32 bit version. They are separate processes. However, the .NET/Link executable must match the DLL that is being loaded.

There is an undocumented option to force loading the 32-bit version of .NET/Link:

InstallNET["Force32Bit" -> True]

Now 32-bit DLLs can be loaded through .NET/Link, but 64-bit ones cannot.

share|improve this answer

Or simply use

ReinstallNET["Force32Bit" -> True]

which is a convenience function that calls

InstallNET["Force32Bit" -> True]
share|improve this answer
I indeed learned ReinstallNET["Force32Bit"->True] in Integrating C and Mathematica by Joel F. Klein and Todd Gayley – unstable May 18 '12 at 8:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.