普通に何にも考えないでビルドされたものを実行するとx64のCLRで起動します。そして当然ですがx64のCLRで起動された場合当然x86のDLLなどをロードすることができません。
そこで自分が作っているものであればプラットフォームをx86に変更すればよいのですがそうではなく誰かが配っているものの場合は困ったりします。
で、とりあえず以下のようなプログラムをx86用アセンブリとしてコンパイルして介して起動することで動くことは動きました。
でもコマンドラインを元に戻すのがちゃんとできてないのでアレソレです。Environment.CommandLine とかEnvironement.GetCommandLineArgs() とかで取ってくるやつはどうにもなりません。きっとどうしてもどうにかしたい人がなんとかしてくれる!
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;
namespace _32bitApplicationStarter
{
static class Program
{
[STAThread]
static void Main(String[] args)
{
if (args.Length == 0)
{
MessageBox.Show("起動したい実行ファイルをドロップ引数に渡してください。", "32bitApplicationStarter", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
Assembly asm = Assembly.LoadFrom(args[0]);
try
{
if (asm.EntryPoint.GetParameters().Length > 0)
{
List<String> argsNew = new List<String>(args);
argsNew.RemoveAt(0);
asm.EntryPoint.Invoke(null, new object[] {argsNew.ToArray()});
}
else
{
asm.EntryPoint.Invoke(null, new object[] {});
}
}
catch (TargetInvocationException e)
{
MessageBox.Show(e.InnerException.ToString(), "32bitApplicationStarter", MessageBoxButtons.OK, MessageBoxIcon.Stop);
throw e.InnerException;
}
}
}
}