【发布时间】:2013-01-31 14:32:53
【问题描述】:
于是我创建了以下测试项目:
[DllImportAttribute("TestMFCDLL.dll", CallingConvention = CallingConvention.Cdecl)]
internal static extern int test(int number);
private void button1_Click(object sender, EventArgs e)
{
int x = test(5);
}
这对于我定义了函数测试的 MFC dll 来说工作得很好,但是我实际上拥有的是许多 MFC dll,它们都共享一个共同的入口函数并根据我的输入以不同的方式运行。所以基本上我有大量的 dll,我在编译时不知道它的名字是什么,我只知道它们具有类似于这个程序的设置方式的功能,有没有办法根据运行时知识导入 dll?简单地这样做会返回一个错误:
static string myDLLName = "TestMFCDLL.dll";
[DllImportAttribute(myDLLName, CallingConvention = CallingConvention.Cdecl)]
属性参数必须是常量表达式,typeof 表达式 或属性参数类型的数组创建表达式
【问题讨论】: