C# form from DLL loaded by native C++ -


this question arising thread: native c++ use c# dll via proxy c++ managed dll

in nutshell, i'm loading (my) c# extension native process via dll. extension needs show form user can control it. i'm using standard .net forms, no 3rd party librarys or anything, , form not showing up. worse yet, hangs target process. it's not using cpu, feeling waiting function return, never does.

also of interest "initialize method" message box pops up, not "test" message box. i've tested can think of (stathread, threads, disablethreadlibrarycalls, plus different code locations), every way sunday. i'm inclined think it's obscure detail of win32 interop, can't find seem cause these symptoms.

can 1 of experts take @ code , point out issue is?

/// <summary> /// provides entry points native code /// </summary> internal static class unmanagedexports {    [unmanagedfunctionpointer(system.runtime.interopservices.callingconvention.stdcall)]    public delegate int sendrecv([marshalas(unmanagedtype.safearray)]byte[] bytearray, uint64 len);     [stathread]    [dllexport("initialize", callingconvention.stdcall)]    public static int initialize(intptr hinstance, sendrecv send, sendrecv recv)    {        return dllinterface.initialize(hinstance, send, recv);    }     [dllexport("terminate", callingconvention.stdcall)]    public static void terminate()    {        dllinterface.terminate();    } }  internal class dllinterface {    static system.threading.thread uithread;     [stathread]    internal static int initialize(intptr hinstance, unmanagedexports.sendrecv send, unmanagedexports.sendrecv recv)    {        messagebox.show("initialize method");        try        {            uithread = new system.threading.thread(run);            uithread.start();        }        catch (exception ex)        {            messagebox.show("failed load: " + ex.message, "infralissa error", messageboxbuttons.ok, messageboxicon.error);        }        return 1;    }     [stathread]    private static void run()    {        messagebox.show("test");         application.enablevisualstyles();        application.setcompatibletextrenderingdefault(false);        application.run(new form1());    }     internal static void terminate()    {        messagebox.show("terminating.");        if (uithread.isalive)            uithread.abort();    } } 

it seems target @ fault. wasn't loading extensions directly, instead loading native "exensionmanager.dll", where, luck have it, using dllmain load extension. in other words, trying load form under loaderlock , ran deadlock as. net tried load other assemblies.

the answer simple, had show form on new thread. however, .net's threading hanging, it, too, required library load deadlocked.

in end, had resort vanilla p/invoke createthread() directly, form showing up.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -