V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
aaronhua
V2EX  ›  C#

求助:用 C#调用第三方控件 ocx,报错!

  •  
  •   aaronhua · 2019-09-11 21:47:50 +08:00 · 10511 次点击
    这是一个创建于 1680 天前的主题,其中的信息可能已经有所发展或是发生改变。

    平常用 python。因为需要调用第三方控件的方法,摸索着使用 c#,网上关于 ocx 控件的教程很少,举步维艰。希望各位大佬能指点下问题。 C#小白,轻喷谢谢!!!

    代码:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using AxXX;
    
    namespace WindowsFormsControlLibrary2
    {
        public partial class UserControl1: UserControl
        {
            public UserControl1()
            {
                InitializeComponent();
    
            }
    
            private void UserControl1_Load(object sender, EventArgs e)
            {
                AxXX xx = new AxXX();
                ((System.ComponentModel.ISupportInitialize)(xx)).BeginInit();
                this.Controls.Add(xx);
                ((System.ComponentModel.ISupportInitialize)(xx)).EndInit();
                xx.AddImage("168", "123", 1, 90);            
            }
        }
    }
    

    异常:

    System.BadImageFormatException
      HResult=0x8007000B
      Message=未能加载文件或程序集“file:///C:\Users\aaronhua\Desktop\dllproject\WindowsFormsControlLibrary2\WindowsFormsControlLibrary2\obj\x86\Debug\WindowsFormsControlLibrary2.dll”或它的某一个依赖项。试图加载格式不正确的程序。
      Source=mscorlib
      StackTrace:
       at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
    
    1 条回复    2019-09-12 10:05:34 +08:00
    ItFunly
        1
    ItFunly  
       2019-09-12 10:05:34 +08:00
    选择 x86 或 x64 编译
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3747 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 10:28 · PVG 18:28 · LAX 03:28 · JFK 06:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.