How to implement interface of C# use COM of native C++?


i'm using .net core in cross platform, include windows , linux.

i can't use atl.

i embed the. net core executable program.

i hope expose c++ class instance pointer .net core(c#), , convert interface of c#.

c++:

class foo : public idispatch, public imanagedobject, public iinspectable...{} fobj;

extern "c" __declspec(dllexport) foo* winapi gettestobject(){return new foo;}

c#:

[dllimport("foo.dll")]

static extern intptr gettestobject();

[guid("48df8e89-57de-3599-ad7c-b49500ef01c0")]
interface itest
{
   int func();
}

main(){

    var v = gettestobject();
    var obj = (itest)marshal.getobjectforiunknown(v);
    obj.func();// exception

    dynamic dobj = marshal.getobjectforiunknown(v);

    dobj.func();// ok, idispatch::invoke called

}

i hope implement interface test of c#.


[interfacetype(cominterfacetype.interfaceisidispatch)]

interface itest{...}

is ok, c++::foo::invoke(idispatch) called.



.NET Framework  >  Common Language Runtime Internals and Architecture



Comments

Popular posts from this blog

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

Azure DocumentDB Owner resource does not exist

SQL Server 2008 - High Memory Usage