CodeDom 参考 VB6 dll
我将 .dll 文件(从 Visual Studio 生成)添加到 CodeDom 生成的可执行文件中没有出现任何问题。为此,我一直使用以下代码:
代码:
string[] referenceAssemblies = {
"System.dll",
"System.Windows.Forms.dll",
"System.Drawing.dll",
"System.Data.dll",
"System.Xml.dll"
};
// Add the referenced assemblies to the compiler parameteres
CompilerParameters cp = new CompilerParameters(referenceAssemblies, exeFile, false);
但是,我现在想添加一个 Visual Basic 6 制作的 .dll 文件作为对 CodeDom 生成的可执行文件的引用。但我不,但想将此 .dll 文件添加为嵌入文件。我希望 .dll 文件相当于在 Visual Studio 中执行以下操作:
从 Visual Studio:
- 打开 Visual Studio >新的Windows窗体应用程序
- 参考文献>>添加参考> Com 参考
- 使用以下
代码调用名为“Test(foo as string)”的函数:
Project1.Class1 vb6Test = new Project1.Class1();
vb6Test.Test("Some String");
从 Visual Basic 6:
- 新建项目>属性> Active X Dll
- 使用 Public 修饰符创建新的类模块并添加以下函数:
- Create Project1.dll
代码:
public Function Test(foo as String)
MsgBox(foo)
End Function
现在,从 Visual Studio 我可以添加 Project1.dll 作为对我的 winform 应用程序的引用并使用上面的代码调用它(在 Visual Studio 部分)。我想通过使用 CodeDom 合并完全相同的功能。但是,我在代码生成过程中遇到 CodeDom 错误:
CodeDom 代码 - 包含 .dll 文件作为引用的程序集:
string[] referenceAssemblies = {
"System.dll",
"System.Windows.Forms.dll",
"System.Drawing.dll",
"System.Data.dll",
"System.Xml.dll",
@"C:\Users\EVAN\Desktop\file.dll"
};
错误:
无法打开元数据文件“c:\Users\EVAN\Desktop\file.dll”-“尝试加载格式不正确的程序。 '
我不知道问题是什么,因为当我手动加载它作为参考时,Visual Studio 没有问题。
我迫不及待地想听听你们都说什么!
谢谢你,
埃文
I have had no problems adding .dll files (generated from Visual Studio) to a CodeDom generated executable file. To do so, I have been using the following code:
Code:
string[] referenceAssemblies = {
"System.dll",
"System.Windows.Forms.dll",
"System.Drawing.dll",
"System.Data.dll",
"System.Xml.dll"
};
// Add the referenced assemblies to the compiler parameteres
CompilerParameters cp = new CompilerParameters(referenceAssemblies, exeFile, false);
However, I would now like to add a Visual Basic 6 made .dll file as a reference to a CodeDom generated executable file. I do NOT, however want to add this .dll file as an embedded file. I want the .dll file to be the equivalent to doing the following in Visual Studio:
From Visual Studio:
- Open Visual Studio > New windows forms application
- References > Add Reference > Com Reference
- Call a function named 'Test(foo as string)' using the following
code:
Project1.Class1 vb6Test = new Project1.Class1();
vb6Test.Test("Some String");
From Visual Basic 6:
- New Project > Properties > Active X Dll
- Create new Class Module with Public modifiers and add in the following function:
- Create Project1.dll
Code:
public Function Test(foo as String)
MsgBox(foo)
End Function
Now, from Visual Studio I am able to add Project1.dll as a reference to my winform application and call it using the code above (in the Visual Studio section). I want to incorporate the exact same functionalitiy through the use of CodeDom. However, I am encountering a CodeDom error during code generation:
CodeDom code - Including the .dll file as a referenced assembly:
string[] referenceAssemblies = {
"System.dll",
"System.Windows.Forms.dll",
"System.Drawing.dll",
"System.Data.dll",
"System.Xml.dll",
@"C:\Users\EVAN\Desktop\file.dll"
};
Error:
Metadata file 'c:\Users\EVAN\Desktop\file.dll' could not be opened -- 'An attempt was made to load a program with an incorrect format. '
I have no idea what the problem could be as Visual Studio has no problem loading it as a reference, when I do it manually.
I can't wait to hear what you all have to say!
Thank you,
Evan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论