Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8546

NETLink on 64-bit Windows

From Joe Eddy <jceddy@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject NETLink on 64-bit Windows
Date 2012-02-15 09:48 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jhfv2a$spr$1@smc.vnet.net> (permalink)

Show all headers | View raw


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 =
CallingConvention.Winapi)]
	[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;
			}
		}
		else
		{
			return false;
		}
	}

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

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

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

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

NETLink on 64-bit Windows Joe Eddy <jceddy@gmail.com> - 2012-02-15 09:48 +0000

csiph-web