MC.Net indicator referencing COM.DLL  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
johnromeronc
Posts: 23
Joined: 18 Feb 2011
Has thanked: 8 times
Been thanked: 6 times

MC.Net indicator referencing COM.DLL

Postby johnromeronc » 13 Sep 2012

I have some routines I would like to access that are in a COM .dll I have written a program in C# that uses interop to get to the methods and properties. So, it works in a C# environment in VS2010. I add the reference in the project/solution under the COM tab. The issue I have is that in MC.Net editor when right click and try to add it as a reference, it is looking for an assembly. (presumably C#). Sooooo - I am semi literate in C# - what must I do to be able to call 'unmanaged' code - specifically this COM .dll? Do I need to do this via DLLImport? This is 3rd party functions I purchased and I don't have the source.

TIA

John

User avatar
Henry MultiСharts
Posts: 8394
Joined: 25 Aug 2011
Has thanked: 1201 times
Been thanked: 2682 times

Re: MC.Net indicator referencing COM.DLL

Postby Henry MultiСharts » 14 Sep 2012

Hello John,

You can follow this guide or create a Dll wrapper in Visual Studio for your Com Dll and connect this wrapper to MultiCharts .Net using References.

johnromeronc
Posts: 23
Joined: 18 Feb 2011
Has thanked: 8 times
Been thanked: 6 times

Re: MC.Net indicator referencing COM.DLL

Postby johnromeronc » 14 Sep 2012

Henry,

Using that guide is how I did access the COM .dll in my test stand alone program in VS 2010. So are you saying I can add the reference in VS2010 and it will stick when I open the indicator in MC.Net editor? Or, are you saying I need to use the TlbImp method? A more manual approach. If I use the TlbImp method, how would I handle the need for a /R when I compile?

John

User avatar
Henry MultiСharts
Posts: 8394
Joined: 25 Aug 2011
Has thanked: 1201 times
Been thanked: 2682 times

Re: MC.Net indicator referencing COM.DLL

Postby Henry MultiСharts » 14 Sep 2012

You can add the reference in VS2010, but to stick the indicator in MC.Net editor you need to create and use the wrapper.

Alternatively:
MSDN wrote:Although TlbImp is the preferred method for converting COM definitions to C#, it is not always possible to use it (for example, if there is no typelib for the COM definitions, or if TlbImp cannot handle the definitions in the typelib). In these cases, the alternative is to manually define the COM definitions in C# source code using C# attributes. Once you have created the C# source mapping, you simply compile the C# source code to produce the managed wrapper.

The main attributes you need to understand to perform COM mapping are:

ComImport - Marks a class as an externally implemented COM class.
Guid – Used to specify a universally unique identifier (UUID) for a class or an interface.
InterfaceType – specifies whether an interface derives from IUnknown or IDispatch.
PreserveSig – specifies whether the native return value should be converted from an HRESULT to a .NET Framework exception.
Each of these attributes is shown in the context of an actual example in this tutorial.

johnromeronc
Posts: 23
Joined: 18 Feb 2011
Has thanked: 8 times
Been thanked: 6 times

Re: MC.Net indicator referencing COM.DLL

Postby johnromeronc » 17 Sep 2012

Are there othere restrictions when using C# with MC.Net? Addign this to a FAQ would be a good thing.

John

User avatar
Henry MultiСharts
Posts: 8394
Joined: 25 Aug 2011
Has thanked: 1201 times
Been thanked: 2682 times

Re: MC.Net indicator referencing COM.DLL  [SOLVED]

Postby Henry MultiСharts » 18 Sep 2012

johnromeronc wrote:Are there othere restrictions when using C# with MC.Net? Addign this to a FAQ would be a good thing.
John

I have created a small FAQ here
These users thanked the author Henry MultiСharts for the post:
johnromeronc

User avatar
Henry MultiСharts
Posts: 8394
Joined: 25 Aug 2011
Has thanked: 1201 times
Been thanked: 2682 times

Re: MC.Net indicator referencing COM.DLL

Postby Henry MultiСharts » 19 Sep 2012

Here is an example how COM objects can be used via interface and wrapper.
This sample will call a dialogue window FileRun (=Win+R) on the last bar.
Attachments
CallCOMObjectsExmpl.zip
(22 KiB) Downloaded 343 times
These users thanked the author Henry MultiСharts for the post:
johnromeronc


Return to “MultiCharts .NET”