none
添加引用*.dll文件不成功,提示请确保此文件可访问并且是一个有效的程序集或COM组件。不知问题出在哪? RRS feed

  • 问题

  • 添加引用*.dll文件不成功,提示请确保此文件可访问并且是一个有效的程序集或COM组件。查看该*.dll文件的属性都是可读可写的,只是语言为中文繁体。而我用的WIN7及VisualStudio2010都为中文简体版,不知跟这有没有关系?怎样才能正常引用该*.dll文件?
    2014年3月6日 9:14

答案

  • 很好,你不需要做什么添加引用的操作了,只要 BridgeMini.dll 同你的程序集在同一个目录下就行。

    注意 DllImport("BridgeMini.dll", 这类语句,你可以上 MSDN 了解下。

    在你的程序中可以直接添加 BridgeMini.cs 文件,然后使用它提供的方法和类型。

    2014年3月6日 10:06

全部回复

  • 请问你引用的这个 *.dll 是 COM 组件吗?

    2014年3月6日 9:17
  • 不知道啊!是IC厂商提供的驱动文件。有2个文件,BridgeMini.cs/BridgeMini.dll总共不到80K,要不要发给你看看?
    2014年3月6日 9:34
  • 不知道啊!是IC厂商提供的驱动文件。有2个文件,BridgeMini.cs/BridgeMini.dll总共不到80K,要不要发给你看看?

    你把 BridgeMini.cs 中的代码稍微贴一些出来就行。
    2014年3月6日 9:39

  • using System;


    using System.Runtime.InteropServices;

    namespace Megawin_MA101
    {

        public class MA_101
        {
            public const UInt32 USER_DEFINE_ERROR = 0xE0000000;

            public const UInt32 INSUFFICIENT_MOMORY_AVAILABLE       = 0xE0000001;
            public const UInt32 HIDD_GETATTRIBUTES_FAIL             = 0xE0000002;
            public const UInt32 CANNOT_FINDE_THE_DEVICE_SPECIFIED   = 0xE0000003;
            public const UInt32 SEND_DEVICE_CHECKCODE_FAIL          = 0xE0000004;
            public const UInt32 GET_DEVICE_CHECKCODE_FAIL           = 0xE0000005;
            public const UInt32 CHECK_DEVICE_CHECKCODE_FAIL         = 0xE0000006;
            public const UInt32 CALL_WRITE_DATA_TIMEOUT             = 0xE0000007;
            public const UInt32 CALL_READ_DATA_TIMEOUT              = 0xE0000008;
            public const UInt32 ALLOCATE_DEVICE_QUEUE_FAIL          = 0xE0000009;
            public const UInt32 GET_INPUT_REPORT_SIZE_FAIL          = 0xE000000A;
            public const UInt32 DELETE_INPUT_QUEUE_FAIL             = 0xE000000B;

            public const UInt32 UNKNOWFUNCTIONTYPE                  = 0xE000000C;
            public const UInt32 UNKNOWMODETYPE                      = 0xE000000D;
            public const UInt32 SET_CMD_FAIL                        = 0xE000000E;
            public const UInt32 HIDD_SET_FEATURE_FAIL               = 0xE000000F;
            public const UInt32 DEVICE_BUSY                         = 0xE0000010;
            public const UInt32 GET_CMD_FAIL                        = 0xE0000011;
            public const UInt32 OPEN_EXISTING_RETURNED              = 0xE0000012;
            public const UInt32 INTERNAL_THREAD_SHUTDOWN_FAIL       = 0xE0000013;
            public const UInt32 IIC_DEVICEADDRESS_FAIL              = 0xE0000014;
            public const UInt32 IIC_DATA_FAIL                       = 0xE0000015;
            public const UInt32 IIC_TIMEOUT_FAIL                    = 0xE0000016;
            public const UInt32 INVALID_MODE                        = 0xE0000017;
            public const UInt32 HIDD_GET_FEATURE_FAIL               = 0xE0000018;
            public const UInt32 IIC_SIZE_ERROR                      = 0xE0000019;
            public const UInt32 UART_WRITE_TIME_OUT                 = 0XE0000020;
            public const UInt32 IIC_INITIAL_FAIL                    = 0xE0000021; 
            public const UInt32 DEVICE_BUSY_1      = 0xE0000022;
            public const UInt32 DEVICE_BUSY_2      = 0xE0000023;
            public const UInt32 WRITE_DATA_FAIL      = 0xE0000024;
            public const UInt32 READ_DATA_FAIL      = 0xE0000025;
            public const UInt32 IIC_SIZE_EXCEEDS_64K    = 0xE0000026;
            public const UInt32 IIC_TIMEOUT_EXCEEDS_65_SECONDS  = 0xE0000027;

           
            public enum eModeType
            {
                eUART = 0x01,
                eIIC = 0x02,
                eSPI = 0x03,
                eGPIO = 0x04,

            };

            [StructLayout(LayoutKind.Sequential)]
            public class MwBridge
            {
                public uint VID;
                public uint PID;
                public uint ReadTimeOut;
                public uint WriteTimeOut;
                public IntPtr Handle;
            }//end struct MwBridge

            [StructLayout(LayoutKind.Sequential)]
            public class PortIO
            {
                public Byte P0;
                public Byte P1;
                public Byte P2;
                public Byte P3;
                public Byte P4;
            }// end struct PortIO
           
            [StructLayout(LayoutKind.Sequential)]
            public class IO_M
            {
                public Byte Low_Nibble_Control;
                public Byte Low_Nibble_Selector;
                public Byte Hi_Nibble_Control;
                public Byte Hi_Nibble_Selector;
            }// end struct IO_M


            [DllImport("BridgeMini.dll", CharSet = CharSet.Auto)]
            public static extern uint MA101_ConnectBridge(
                [In, MarshalAs(UnmanagedType.LPStruct)] MwBridge pMwBridge,
                                                        uint     Index);

            [DllImport("BridgeMini.dll", CharSet = CharSet.Auto)]
            public static extern uint MA101_DisconnectBridge(
                [In, MarshalAs(UnmanagedType.LPStruct)] MwBridge pMwBridge);

            [DllImport("BridgeMini.dll", CharSet = CharSet.Auto)]
            public static extern uint MA101_WriteData(
                [In, MarshalAs(UnmanagedType.LPStruct)] MwBridge    pMwBridge,
                                                        byte        [] lpBuffer,
                                                        uint        nNumberOfBytesToWrite,
                                                        ref uint    lpNumberOfBytesWritten);

            [DllImport("BridgeMini.dll", CharSet = CharSet.Auto)]
            public static extern uint MA101_ReadData(
                [In, MarshalAs(UnmanagedType.LPStruct)] MwBridge    pMwBridge,
                                                        byte []     lpBuffer,
                                                        UInt32      nNumberOfBytesToRead,
                                                        ref UInt32  lpNumberOfBytesRead);

    2014年3月6日 9:55
  • 很好,你不需要做什么添加引用的操作了,只要 BridgeMini.dll 同你的程序集在同一个目录下就行。

    注意 DllImport("BridgeMini.dll", 这类语句,你可以上 MSDN 了解下。

    在你的程序中可以直接添加 BridgeMini.cs 文件,然后使用它提供的方法和类型。

    2014年3月6日 10:06