Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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#.

Posted

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

  • *Gurus*
Posted

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).

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...