PhilBayley Posted January 10, 2003 Posted January 10, 2003 Im not sure if this is supposed to go here. I am writing an app that will dynamically load an assemblie. I want to send the assemblie a callback address so that I can update a progress bar within the main app. How do I go about this concidering that the assembly knows knothing about the calling app (therefore defining the delegates a little difficult) and taking into account that the app will know nothing about the dll. This used to be very easy with c++ and I have managed to used callbacks from a c# app to a c++ dll without problem but I now want to convert my c++ dll into c#. Quote
*Gurus* divil Posted January 10, 2003 *Gurus* Posted January 10, 2003 How far have you got so far? Is there a reason you can't pass a handle to the Progress Bar itself to the assembly you're loading? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
PhilBayley Posted January 10, 2003 Author Posted January 10, 2003 The reason is legacy. A different team of developers may be writing the dll's. The main function of the app is to load different dll's (to process data in different ways) all of which get started with a function call (i.e StartThread) but in olden days of c++ we would first setup the addresses of certain functions like UpdatePercent (int iPercent) AddErrorMessage(string sTemp) And whilst the main thread was running the c++ dll could call adderrormessage to update a processing screen in the main app. All Ive been able to do so far is load my new c# dll and call a method from it - so no callback functions at all. I have managed to load old c++ dll's and run these by passing delegates to the old callback functions. All seems fine but this new c# stuff just seems to have taken the fun out of pointers :-) Any help would be cool. Ive been researching AsyncCallbacks and remoting but have had no success as yet Quote
*Gurus* divil Posted January 10, 2003 *Gurus* Posted January 10, 2003 Well, both assemblies will need to reference a common assembly where you will define the delegate function that accepts the percentage parameter. There has to be a common point of reference because delegates are type-safe. Then, you can make a method in your host application which has the correct signature and pass that, as the type of the delegate, to your plugin (or whatever the external assemblies are). Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
PhilBayley Posted January 10, 2003 Author Posted January 10, 2003 BRILLIANT! Good idea. I was too stuck on the old way of doing things. I will try this on for size. Thanks Quote
PhilBayley Posted January 13, 2003 Author Posted January 13, 2003 My colleague came up with a novel way to solve my problem, finding functions in the calling program (i didnt realise you could go both ways) Console.WriteLine("Executing Go (in PROJECT.DLL)"); Assembly a = Assembly.GetCallingAssembly(); Type myType = a.GetType("SlFuncs"); MethodInfo mymethod = myType.GetMethod("PhaseList"); Object obj = Activator.CreateInstance(myType); Object[] parameters = new Object[2]; parameters[0] = "Hello"; parameters[1] = 1234; mymethod.Invoke(obj, parameters); just for info if ever you need it and didnt know about it. Phil Quote
Recommended Posts