New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Com Interop in .netcore #8654

Closed
acesiddhu opened this Issue May 18, 2016 · 14 comments

Comments

Projects
None yet
7 participants
@acesiddhu

acesiddhu commented May 18, 2016

Hi,
Is COM interop possible in .net core? I am trying to create a instance of an com interface using RunTimeEnvironment.GetRuntimeInterfaceAsObject. Looks like the api is not present.

@ellismg

This comment has been minimized.

Contributor

ellismg commented May 18, 2016

@ellismg ellismg added the question label May 18, 2016

@ellismg ellismg added this to the Future milestone May 18, 2016

@yizhang82

This comment has been minimized.

Contributor

yizhang82 commented May 18, 2016

@acesiddhu COM interop is supported in WIndows only for .NET Core, and it does not have full support (such as IDispatch) as full .NET framework.
RuntimeEnvironment.GetRuntimeInterfaceAsObject API is not part of .NET Core, because .NET Core does not have the same Com-based runtime interfaces (they don't make sense in cross-plat context) - we are moving to a more flat C-style hosting API. @janvorli should be able to point you to the right set of APIs depending on exactly what you need.

@acesiddhu

This comment has been minimized.

acesiddhu commented May 19, 2016

Is there way to Get instance of IUnknown interface? Specifically I am looking to use IMetaDataDispenser interface.

@yizhang82

This comment has been minimized.

Contributor

yizhang82 commented May 19, 2016

@acesiddhu You can use Marshal.GetObjectForIUnknown to convert it to a RCW (assuming that's what you mean by "get instance of IUnknown interface", or simply have your p/invoke (if any) returns IMetadataDispenser interface. Just keep in mind it is windows only :)

@acesiddhu

This comment has been minimized.

acesiddhu commented May 22, 2016

@yizhang82
the interface resides in kernel32 and not owned by us. Also I need to create an instance of that interface and not actually get :). I saw a similar usage in one of the repo. Is this approach supported?

PS: I am writing code which is build against .net core but for now it is currently available on windows hence I am trying to use COM as of today.

@acesiddhu

This comment has been minimized.

acesiddhu commented May 22, 2016

I can also Call CoCreateInstance. Just wanted to check which one is preferred way in .Net core (given that requirement is to run only on Windows :))

@yizhang82

This comment has been minimized.

Contributor

yizhang82 commented Jun 6, 2016

@acesiddhu Yes, CoCreateInstance should work if you want to create the object:

    [DllImport("ole32.dll")]
    private static extern int CoCreateInstance([in]ref Guid rclsid, IntPtr pUnkOuter,
                                       Int32 dwClsContext,
                                       [in]ref Guid riid,
                                       [MarshalAs(UnmanagedType.Interface)] out object ppv);

Personally that's the way I would go, assuming that you need to create the underlying COM object given a GUID, and simply cast that to a ISomeComInterface to make calls.

@yizhang82

This comment has been minimized.

Contributor

yizhang82 commented Jun 6, 2016

@acesiddhu I'm closing this issue for now. Let me know if you have further questions and feel free to re-open this.

@yizhang82 yizhang82 closed this Jun 6, 2016

@wxb1

This comment has been minimized.

wxb1 commented Oct 28, 2016

@yizhang82
I cannot get load a vb6 style com dll at all. I get a class not registered even though it is. So a vb6 com dll is not supported at all?

` public static void Main(string[] args)
{
var r = Ole32Methods.CoInitialize(new IntPtr(0));

        const uint CLSCTX_INPROC_SERVER = 1;

        Guid clsid = new Guid("C31CBF72-92C6-4A47-A4C4-935706C26D34");

        // GUID of the required interface
        Guid IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046");

        object instance = null;

        uint hResult = Ole32Methods.CoCreateInstance(ref clsid, null,
                       CLSCTX_INPROC_SERVER, ref IID_IUnknown, out instance);

        _ICommonUI sidCUI = instance as _ICommonUI;

        sidCUI.Show(1, null);
    }  `
@yizhang82

This comment has been minimized.

Contributor

yizhang82 commented Oct 31, 2016

@wxb1 My first guess is that you are running .NET Core app under 64-bit (that's the only flavor we support today officially) and your VB6 COM is registered under 32-bit (since it is 32-bit only). The 64-bit/32-bit registry are in different places in registry.

@wxb1

This comment has been minimized.

wxb1 commented Nov 2, 2016

Thanks yizhang82. .Net core is 64-bit only?! I can't use it for my purposes then... Is there any plans for 32-bit? Is there is a time frame?

@yizhang82

This comment has been minimized.

Contributor

yizhang82 commented Nov 2, 2016

@gkhanna79 can you comment on 32-bit plan?

@gkhanna79

This comment has been minimized.

Member

gkhanna79 commented Nov 2, 2016

We do have .NET Core for Windows x86. The installers/downloads are available at https://www.microsoft.com/net/download#core.

@karelz karelz modified the milestones: Future, 1.2.0, 1.1.0 Dec 3, 2016

@ztl8702

This comment has been minimized.

ztl8702 commented Jun 8, 2018

Is it possible to make a COM server in .NET Core, by using something like ComVisible?

Additionally, is it possible to compile this COM-visible assembly to a native Windows dll? (By using CoreRT)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment