English 中文(简体)
在管理(C#)的法典中实施“汇合”
原标题:Implementing a COM "sink" in managed (C#) code
  • 时间:2009-11-25 16:28:40
  •  标签:
  • c#
  • iunknown

我有一个遗产控制(Core),接受“IUn known到ink。 目的是通过这一汇合界面使核心能够读/篡改数据。 核心/汇点目前在遗产系统中使用,不易修改。

问题Im在于,我试图将核心从管理法中提出来,并在一个目标(目标)上通过,以实施管理法中的思维。 我把这个核心.倒在准备把这个思想叫上。 在发出这一呼吁之前(而不是之后),我收到以下信息:

停工检查失败 #0 - 在整个功能电话中,ESP的价值没有得到适当维护......

我亲眼看到并努力采用纯粹的遗产法,但采用有管理的守则是很费力的。

这里是我认为有必要的两个接口中最小的代表。

interface ICore : IDispatch
{
   [id(1), helpstring("method Init")] HRESULT Init([in] IUnknown *pDataManSink);

  HRESULT FireOnImport([in] LPCOLESTR pszFormName, [in] LPCOLESTR pszTagName, [in] VARIANT pszData);

   ... more methods
}

从IDL(为了缓解问题的示范而减少)获得的数据

interface IDataManagerSinkEx : IUnknown
{
   [helpstring("method ReadData")] HRESULT ReadData([in] LPCTSTR pszDataKey, [out, retval] BSTR* pbsData);
   [helpstring("method WriteData")] HRESULT WriteData([in] LPCTSTR pszDataKey, [in] LPCTSTR pszData);
   [helpstring("method ReadDataEx")] HRESULT ReadTagEx([in] LPCTSTR pszDataKey, [out] short *pwExtraInfoOut, [out, retval] BSTR *pbsData);
   [helpstring("method WriteDataEx")] HRESULT WriteTagEx([in] LPCTSTR pszDataKey, [in] short wExtraInfo, [in] LPCTSTR pszData);
}

我尝试了C#中的各种智囊,以防出现错误。 这里是最目前的执行,是,我手把接口定义编码,因为从类型平衡中采用这一定义并不可行。 (同一问题)

[ComImport]
[Guid( "AB79770E-8143-45E6-B082-E985E6DFA5CB" )]
[InterfaceType( ComInterfaceType.InterfaceIsIUnknown )]
public interface IMyDataManagerSinkEx
{
  [PreserveSig]
  int ReadData( [MarshalAs( UnmanagedType.LPStr )]string pszDataKey, out string data );

  [PreserveSig]
  int WriteTag( [MarshalAs( UnmanagedType.LPStr )]string pszDataKey, [MarshalAs( UnmanagedType.LPStr )]string pszData );

  [PreserveSig]
  int ReadTagEx( [MarshalAs( UnmanagedType.LPStr )]string pszDataKey, out short pwExraInfoOut, out string dataOut );

  [PreserveSig]
  int WriteTagEx( [MarshalAs( UnmanagedType.LPStr )]string pszDataKey, short wExtraInfo, [MarshalAs( UnmanagedType.LPStr )]string pszData );
}

class public SinkImpl : IMyDataManagerSinkEx
{
  [PreserveSig]
  public int ReadData( [MarshalAs( UnmanagedType.LPStr )]string pszDataKey, out string data )
  {
     throw new NotImplementedException();
  }

  [PreserveSig]
  public int WriteTag( [MarshalAs( UnmanagedType.LPStr )]string pszDataKey, [MarshalAs( UnmanagedType.LPStr )]string pszData )
  {
     throw new NotImplementedException();
  }

  [PreserveSig]
  public int ReadTagEx( [MarshalAs( UnmanagedType.LPStr )]string pszDataKey, out short pwExraInfoOut, out string dataOut )
  {
     throw new NotImplementedException();
  }

  [PreserveSig]
  public int WriteTagEx( [MarshalAs( UnmanagedType.LPStr )]string pszDataKey, short wExtraInfo, [MarshalAs( UnmanagedType.LPStr )]string pszData )
  {
     throw new NotImplementedException();
  }
}
问题回答

ESP问题通常意味着,你在达格·哈马舍尔德图书馆运行时间之间有某种组合。 例如,在我们的代码基数中,如果目前对这些物体中的某些物体的COM登记来自装饰建筑,而另一些则登记为释放版本,那么当这些物体的界面上要求使用这些方法时,你就会发现ESP错误。

我有一份说明,登记了我们编码数据库中所有已知的COM物体。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签