The .NET/Link tutorial shows how to call functions defined in DLLs. The example uses the GetTickCount
Win32 API function
<< NetLink`
InstallNET[]
getTickCount = DefineDLLFunction["GetTickCount", "kernel32.dll", "int", {}]
getTickCount[]
(* ==> 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", {}]
getTickCount[]
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?