aaronhua
V2EX  ›  C#

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

  •  
  •   aaronhua · Sep 11, 2019 · 11516 views
    This topic created in 2436 days ago, the information mentioned may be changed or developed.

    平常用 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 replies    2019-09-12 10:05:34 +08:00
    ItFunly
        1
    ItFunly  
       Sep 12, 2019
    选择 x86 或 x64 编译
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4934 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 01:06 · PVG 09:06 · LAX 18:06 · JFK 21:06
    ♥ Do have faith in what you're doing.