[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(4)]
        public virtual extern void SetData(int inType, int inColor, [MarshalAs(UnmanagedType.BStr)] string inData);想知道inData往里传什么样子的值?

解决方案 »

  1.   

    string 报错:对 COM 组件的调用返回了错误 HRESULT E_FAIL。
      

  2.   

    传什么值根据方法的需要啊,UnmanagedType.BStr 只是约定参数封送方式,E_FAIL 多半是你值内容不对,跟格式无关
      

  3.   

    [ComImport, Guid("3322C367-43AE-4E6B-A0FE-6A9B50850A10"), ClassInterface(ClassInterfaceType.AutoDispatch), TypeLibType(2)]
      public class MSClass  
      {
      [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(4)]
      public virtual extern void SetData(int Type, int Color, [MarshalAs(UnmanagedType.BStr)] string Data);
        
      }
    这是我在DLL写的
    但我在引入这个dll后用
    ms.SetData(1,0, "dlllll");   
    不好用,总是提示
    对 COM 组件的调用返回了错误 HRESULT E_FAIL。