本文介绍了具有C ++/CLI的多个AppDomain的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从本机可执行文件开始的解决方案,然后加载一个c ++/cli库,我们将调用MyProj.Interop,然后加载ac#lib,我们将调用MyProj.Manager,它创建了沙箱.这个新的AppDomain加载了一个 新的库,我们将调用MyProj.Sandbox,该库将加载MyProj.Interop,然后创建一个回调接口的新实例(以前在旧的appdomain中创建了一个实例),然后将该实例注册在本机可执行文件中.现在,托管回调管理器 或多或少是这样编码的:

I have a solution that starts out as a native executable which then loads a c++/cli library we will call MyProj.Interop which in turn loads a c# lib we will call MyProj.Manager which creates an AppDomain needed for sandboxing. This new AppDomain loads a new library we will call MyProj.Sandbox which loads MyProj.Interop and then creates a new instance of a callback interface (one was previously created in the old appdomain) which is then registered in the native executable. Now the managed callback manager is coded more or less like this:

 

 

class CListener : public ICallback
{
private:
	gcroot<IListener^> m_Listener;

public:
	CListener(IListener^ listener);
	~CListener(void);

	IListener^ GetListener();

	virtual void OnCallback();
};

推荐答案

http://www.lenholgate.com /blog/2009/07/error-cannot-pass-a-gchandle-across-appdomains.html


这篇关于具有C ++/CLI的多个AppDomain的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 15:30