CodeDom 参考 VB6 dll

发布于 2024-12-08 12:24:55 字数 2452 浏览 0 评论 0原文

我将 .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:

  1. 打开 Visual Studio >新的Windows窗体应用程序
  2. 参考文献>>添加参考> Com 参考
  3. 使用以下

代码调用名为“Test(foo as string)”的函数:

Project1.Class1 vb6Test = new Project1.Class1();
                vb6Test.Test("Some String");

从 Visual Basic 6:

  1. 新建项目>属性> Active X Dll
  2. 使用 Public 修饰符创建新的类模块并添加以下函数:
  3. 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:

  1. Open Visual Studio > New windows forms application
  2. References > Add Reference > Com Reference
  3. 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:

  1. New Project > Properties > Active X Dll
  2. Create new Class Module with Public modifiers and add in the following function:
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文