如果您观察下图,我的“RSR.exe”应用程序运行良好,因为两个 .dll 位于同一文件路径上;但是,如果这 2 个 .dll 与 RSR.exe 不在同一文件路径/目录中,则会导致崩溃/“程序已停止工作”。
这是我尝试使用但没有成功的以下代码。
public static MainForm _mainForm;
static string subPath = @"C:\Users\Public\Documents\RSR";
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
if (!Directory.Exists(subPath))
{
Directory.CreateDirectory(subPath);
if (IntPtr.Size == 4)
{
File.WriteAllBytes("C:\\Users\\Public\\Documents\\RSR\\MouseKeyboardActivityMonitor.dll", Properties.Resources.MouseKeyboardActivityMonitor);
File.WriteAllBytes("C:\\Users\\Public\\Documents\\RSR\\WindowsFormsAero.dll", Properties.Resources.WindowsFormsAero);
}
else
{
File.WriteAllBytes("C:\\Users\\Public\\Documents\\RSR\\MouseKeyboardActivityMonitor.dll", Properties.Resources.MouseKeyboardActivityMonitor1);
File.WriteAllBytes("C:\\Users\\Public\\Documents\\RSR\\WindowsFormsAero.dll", Properties.Resources.WindowsFormsAero);
}
}
AssemblyName asm1 = AssemblyName.GetAssemblyName(@"C:\Users\Public\Documents\RSR\MouseKeyboardActivityMonitor.dll");
Assembly.Load(asm1);
AssemblyName asm2 = AssemblyName.GetAssemblyName(@"C:\Users\Public\Documents\RSR\WindowsFormsAero.dll");
Assembly.Load(asm2);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (_mainForm = new MainForm())
{
Application.Run(_mainForm);
}
Cursor normalCursor1 = new Cursor(new System.IO.MemoryStream(Properties.Resources.cursor_normal));
SetSystemCursor(normalCursor1.Handle, 32512);
}
这是当 2 个 .dll 不在同一目录/路径中时的崩溃信息的下图。
任何援助将不胜感激。
谢谢。