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


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

NETLink on 64-bit Windows

Started byJoe Eddy <jceddy@gmail.com>
First post2012-02-15 09:48 +0000
Last post2012-02-15 09:48 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

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

#8546 — NETLink on 64-bit Windows

FromJoe Eddy <jceddy@gmail.com>
Date2012-02-15 09:48 +0000
SubjectNETLink on 64-bit Windows
Message-ID<jhfv2a$spr$1@smc.vnet.net>
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();
    }

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web