提问人:ks2 提问时间:10/17/2023 最后编辑:ks2 更新时间:10/17/2023 访问量:24
使用委托将数据从一个库传递到另一个库,再到应用程序
Pass data from one library to another library to application using delegate
问:
CameraManager.dll 将静态链接到应用程序。有一个相机 dll(MyCam1.dll),它将根据选定的相机动态加载。
我想将图像传输到主应用程序。我不确定如何在CameraManager.dll中注册委托!我是否需要编写另一个委托来将图像从相机管理器.dll传输到应用程序?
lib1:相机管理器.dll
public Interface ICamera
{
void InitCam();
void CloseCam();
void SetGain();
void SetBrightness();
}
public class CameraCollection
{
public void createCamInstance()
{
ICamera Camob = instance.InitCam();
}
//load library dynamically.
public void LoadCamera()
{
Assembly DLL = Assembly.LoadFrom(@"c:\MyCam*.dll");
foreach (Type type in DLL.GetTypes())
{
if (type.FullName == "Mycam")
{
instance = Activator.CreateInstance(type);
}
}
}
}
/////////////////////////////////////////////////////////////
lib2: MyCam1.dll
public delegate void ImageGrabDone(byte[] data);
public class Mycam:ICamera{
public event ImageGrabDone GrabEvent;
void ICamera.InitCam()
{
//some initialization stuff
}
void ImageGrabbed()
{
// This function will be called automatically when camera gets triggered.
//from Here I want to pass Image/byte[] to CameraManager.dll and from CameraManager to
//host application.
}
}
答: 暂无答案
评论