我用C#做了一个winform程序A,并将其加密压缩。然后在另一个程序B中先将A解密还原,并使用反射的方式动态加载该程序集A。由于在A中使用了一些COM组件,在打开相关窗口时及提示“当前线程不在单线程单元中,因此无法实例化 ActiveX 控件”错误!,郁闷了好久也没解决。
程序B中加载程序集的代码如下:
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[System.Runtime.InteropServices.DllImport("Check")]
private static extern bool DecodeFile(Byte[] data, out long dwLen);
static void Main()
{
long nLen = 0;
Byte[] bs = new Byte[2100000]; if (DecodeFile(bs, out nLen))
{
Assembly asm = Assembly.Load(bs);
MethodInfo info = asm.EntryPoint;
ParameterInfo[] parameters = info.GetParameters();
if ((parameters != null) && (parameters.Length > 0))
info.Invoke(null, (object[])args);
else
info.Invoke(null, null);
}
else
{
MessageBox.Show("启动程序失败,请及时联系技术服务!", "提示");
}
}
}
其中DecodeFile是用vc做的一个解密函数,用于还原程序集A
请各位帮忙看下,怎么解决,谢谢!
程序B中加载程序集的代码如下:
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[System.Runtime.InteropServices.DllImport("Check")]
private static extern bool DecodeFile(Byte[] data, out long dwLen);
static void Main()
{
long nLen = 0;
Byte[] bs = new Byte[2100000]; if (DecodeFile(bs, out nLen))
{
Assembly asm = Assembly.Load(bs);
MethodInfo info = asm.EntryPoint;
ParameterInfo[] parameters = info.GetParameters();
if ((parameters != null) && (parameters.Length > 0))
info.Invoke(null, (object[])args);
else
info.Invoke(null, null);
}
else
{
MessageBox.Show("启动程序失败,请及时联系技术服务!", "提示");
}
}
}
其中DecodeFile是用vc做的一个解密函数,用于还原程序集A
请各位帮忙看下,怎么解决,谢谢!
散发,谢谢各位!