Wrapping MFC Objects for Remoting

One serious limitation when using remoting is that you cannot remote MFC objects across application domains. Consider the following two classes that we can attempt to remote:

namespace SecondDll
{
  public __gc class StrWrapper : public MarshalByRefObject
  {
  public:
    StrWrapper(CStringArray* list)
    {
      m_list = list;
    }
    CStringArray* m_list;
  };


  public __gc class WebList : public MarshalByRefObject
  {
  private:
    CStringArray* m_list;
  public:
    WebList()
    {
      m_list = new CStringArray();
      m_list->Add(S"Amazon");
      m_list->Add(S"Rediff");
      m_list->Add(S"Yahoo");
      m_list->Add(S"Google");
    }
    ~WebList()
    {
      delete m_list;
    }
    CStringArray* GetList()
    {
      return m_list;
    }
    StrWrapper* GetList2()
    {
      return new StrWrapper(m_list);
    }
  };

}

Essentially ...

Get Extending MFC Applications with the .NET Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.