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

2019-09-11 21:47:50 +08:00
 aaronhua

平常用 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)
10533 次点击
所在节点    C#
1 条回复
ItFunly
2019-09-12 10:05:34 +08:00
选择 x86 或 x64 编译

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/600181

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX