For a C++ project you should be able to add a 64-bit build target like so:
1. Right click on the project in the Solution Explorer, then click on Properties
2. Click on "Configuration Manager..." in the upper right. Right now you probably only have "Win32".
3. Under "Active Solution Platform", choose "New..."
4. Choose "x64" under "Type or select the new platform". Under "Copy settings from", make sure it says Win32, and make sure the checkbox for "Create new project platforms" is enabled.
5. Click all the OK buttons until you're back out of the dialog boxes.
6. Now in the toolbar you should be able to choose "Release" or "Debug", as well as "Win32" or "x64".
Once you compile the 64-bit DLL, rename it to something like SquishInterface_x64.dll. Then, in your C# code, you will want to structure your NativeMethods like so:
Code:
using System.Runtime.InteropServices;
internal sealed class NativeMethods
{
private static bool is64bit;
static NativeMethods()
{
is64bit = (Marshal.SizeOf(IntPtr) == 8);
}
/// trampoline function for SquishInterface[_x64].dll::SomeFunction
internal static int SomeFunction(int param1, int param2)
{
if (is64bit)
{
return NativeMethods_64.SomeFunction(param1, param2);
}
else
{
return NativeMethods_32.SomeFunction(param1, param2);
}
}
private sealed class NativeMethods_32
{
[DllImport("SquishInterface.dll")]
public static extern int SomeFunction(int param1, int param2);
}
private sealed class NativeMethods_64
{
[DllImport("SquishInterface_x64.dll")]
public static extern int SomeFunction(int param1, int param2);
}
}
Essentially for each P/Invoke you have, you must import both the 32-bit and 64-bit version, and then have a trampoline that figures out which one to call. If you have a
lot of methods that you're importing for P/Invoke then this can be a major hassle, but that should be easy to solve by writing a quick code generation program that does reflection on your existing NativeMethods class.
Let me know if you have any other questions.