MathGroup Archive 2012

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

Search the Archive

NETLink on 64-bit Windows

  • To: mathgroup at
  • Subject: [mg124982] NETLink on 64-bit Windows
  • From: Joe Eddy <jceddy at>
  • Date: Wed, 15 Feb 2012 04:45:36 -0500 (EST)
  • Delivered-to:

Just thought I'd post this as it might be useful to someone else in
the future.

We were having a helluva time getting .NET/Link to work properly on a
64-bit Windows machine.  I ended up going through the provided source
code to try to find the problem.  I saw that there is a class provided
called "Win64MathLinkAPIProvider.cs", but that the class wasn't used
by any of the internal code.

Rather, in the static constructor for NativeLink, it looks like if
you're running on Windows, it always uses
"WindowsMathLinkAPIProvider.cs", which appears to only work correctly
on a 32-bit OS.  I made the change below and re-compiled (note: I re-
compiled against .NET Framework v2.0, as well, since it seems that
v1.1 doesn't play nice with 64-bit), dropped it in, and everything
worked.  I also verified that it works correctly on our older 32-bit
machines.  This seems to be somewhat of an oversight on Wolfram's
part, but maybe it just never came up?

If anyone has found a better solution, please let me know.

Code that changed (in NativeLink.cs):

	/*************************************  Added By Joe
	[DllImport("kernel32.dll", SetLastError = true, CallingConvention =
	[return: MarshalAs(UnmanagedType.Bool)]
	private static extern bool IsWow64Process(
		[In] IntPtr hProcess,
		[Out] out bool wow64Process

	static bool InternalCheckIsWow64()
		if ((Environment.OSVersion.Version.Major == 5 &&
Environment.OSVersion.Version.Minor >= 1) ||
			Environment.OSVersion.Version.Major >= 6)
			using (Process p = Process.GetCurrentProcess())
				bool retVal;
				if (!IsWow64Process(p.Handle, out retVal))
					return false;
				return retVal;
			return false;

    /*************************************  Constructors

	// Note: Joe added 64-bit checks
    static NativeLink() {
		if (Utils.IsWindows)
			bool is64BitProcess = (IntPtr.Size == 8);
			bool is64BitOperatingSystem = is64BitProcess ||

			if (is64BitOperatingSystem)
				api = new Win64MathLinkAPIProvider();
				api = new WindowsMathLinkAPIProvider();
		else if (Utils.IsMac)
			api = new MacMathLinkAPIProvider();
			api = new UnixMathLinkAPIProvider();
        env = api.extMLBegin(IntPtr.Zero);
        envLock = new object();

  • Prev by Date: Re: simple question on DSolve
  • Next by Date: Re: Running MathematicaScript in Mac Terminal
  • Previous by thread: Re: Using .NET/Link on 64-bit Windows Server 2008
  • Next by thread: two ordinate graphics in MA