首页 新闻 会员 周边 捐助

C# ActiveX(OCX)组件开发 托管与非托管问题

0
悬赏园豆:10 [待解决问题]

目前在开发标题中的组件,在组件中需要调用第三方C++版本的DLL库,该库用于视频设备的操控,并且该组件运行在JSP页面中,DLL库中需要相关的Struct的封装,下面将列出:

        [StructLayoutAttribute(LayoutKind.Explicit)]
        public struct WIFI_AUTH_PARAM
        {
            [FieldOffsetAttribute(0)]
            public UNION_EAP_TTLS EAP_TTLS;

            [FieldOffsetAttribute(0)]
            public UNION_EAP_PEAP EAP_PEAP;

            [FieldOffsetAttribute(0)]
            public UNION_EAP_TLS EAP_TLS;
        }

结构体中第一个Struct我将进行说明:

[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Size = 144)]
        public struct UNION_EAP_TTLS
        {
            public byte byEapolVersion;
            public byte byAuthType;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 2, ArraySubType = UnmanagedType.I1)]
            public byte[] byRes1;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = NAME_LEN, ArraySubType = UnmanagedType.I1)]
            public byte[] byAnonyIdentity;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = NAME_LEN, ArraySubType = UnmanagedType.I1)]
            public byte[] byUserName;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = NAME_LEN, ArraySubType = UnmanagedType.I1)]
            public byte[] byPassword;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 44, ArraySubType = UnmanagedType.I1)]
            public byte[] byRes;
        }

但是在运行时遇到错误:Error    13    Cannot register assembly "D:\Code\NET\Casic.ActiveX\Casic.ActiveX\bin\Debug\Casic.ActiveX.dll". Could not load type 'WIFI_AUTH_PARAM' from assembly 'Casic.ActiveX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 0 that is incorrectly aligned or overlapped by a non-object field.

如果去掉项目-》属性 -》Build (Register for COM interop)选项,则编译顺利通过,请各位帮帮忙,谢谢大家!

问题补充:

OCX组件的注册属于Windows的托管代码,不支持非托管代码原因导致???求解

闪烁光辉的主页 闪烁光辉 | 初学一级 | 园豆:192
提问于:2014-09-19 10:20
< >
分享
所有回答(3)
0

关注!

519740105 | 园豆:5810 (大侠五级) | 2014-09-19 10:30
0

楼主解决了没?

刘宏玺 | 园豆:14020 (专家六级) | 2014-11-14 12:51
0

使用管理员身份运行IDE

性能疯子 | 园豆:206 (菜鸟二级) | 2015-09-01 18:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册