c# - Controlling a WPF app from a DLL (interprocess communication) -
i have dll has talk programme not written in c#. have established connection code:
namespace classlibrary1 { public class class1 { [dllexport("teststring", callingconvention = system.runtime.interopservices.callingconvention.stdcall)] [return: marshalas(unmanagedtype.bstr)] public static string teststring(string test) { homecoming "test" + test; } public static callbackproc _callback; [dllexport("setcallback", callingconvention = system.runtime.interopservices.callingconvention.stdcall)] public static void setcallback(callbackproc pcallback) { _callback = pcallback; //var app = new app(); //var win = new mainwindow(); //app.run(win); messagebox.show("c#: setcallback completed"); } [dllexport("testcallback", callingconvention = system.runtime.interopservices.callingconvention.stdcall)] public static void testcallback(string passedstring) { string displayvalue = passedstring; string returnvalue = string.empty; todaybutton.mainwindow app = new todaybutton.mainwindow(); app.initializecomponent(); messagebox.show("c#: phone call callback. displayvalue=" + displayvalue + ", returnvalue=" + returnvalue); _callback(displayvalue, ref returnvalue); messagebox.show("c#: callback. displayvalue=" + displayvalue + ", returnvalue=" + returnvalue); } public delegate void callbackproc( [marshalas(unmanagedtype.bstr)] string passedvalue, [marshalas(unmanagedtype.bstr)] ref string returnvalue); } }
so callbacks work perfectly. have problem dont know how solve. want utilize interface wpf app. when programme calls dll, dll should start wpf app , wait app close , send information, phone call callback.
the thing dont want start , stop wpf app everytime need info it. want have button "send callback". problem project class library, using dllexport , wpf project won't compile class library.
is there way this, can command whole wpf app dll? command start, stop, pass callback values phone call them wpf forms, or send info testcallback
function when press button in wpf.
how possible?
in end have decided i'm gonna utilize simple messaging library since have winforms on dll side , wpf on other side, utilize windows messages. http://thecodeking.github.io/xdmessaging.net/ library used.
another, more advanced way of sharing info http://blogs.msdn.com/b/dmetzgar/archive/2012/10/16/an-updated-custom-wcf-transport-channel-example.aspx wanted utilize in end decided i'm not gonna utilize wcf since i'm not sending alot of data, messages command app.
c# .net wpf dll
No comments:
Post a Comment