Equivalent code of CreateObject in C#

后端 未结 3 1703
孤独总比滥情好
孤独总比滥情好 2020-11-28 08:49

I have a code in VB6. Can anyone tell me how to write it in C#. This code is below:

Set Amibroker = CreateObject(\"Broker.Application\")
Set STO         


        
3条回答
  •  日久生厌
    2020-11-28 09:33

    Here's a snippet from the C# code I used to automate Amibroker (from when I went down that path). You'll need to reference System.Runtime.Interopservices

        System.Type objType = System.Type.GetTypeFromProgID("Broker.Application");
    
        dynamic comObject = System.Activator.CreateInstance(objType);
    
        comObject.Import(0, fileName, "default.format");
    
        comObject.RefreshAll();
    

    Typing a dot won't bring up the comObject internal methods, though.

    All I can say about this method is - it works, like a charm, but stay away from it, like David said. I got my inspiration for this method from:

    http://www.codeproject.com/Articles/148959/How-the-new-C-dynamic-type-can-simplify-access-to

    For another angle of attack, you may want to check out (I think this is early binding):

    http://adamprescott.net/2012/04/05/net-vb6-interop-tutorial/

    Hope at least some of this help you. I've used both these methods with Amibroker and C#, but I ended up leaving them behind. COM and Amibroker don't mix well. Even TJ says so.

    Good luck anyway.

提交回复
热议问题