CodeDom Reference VB6 dll

我是研究僧i 提交于 2019-12-11 02:38:36

问题


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

来源:https://stackoverflow.com/questions/7667095/codedom-reference-vb6-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!