• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

cannot call DLL method into indicator

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    cannot call DLL method into indicator

    Hello
    I'm trying to develop indicator which gets the data from external sources. For this purposes I've got C++/CLI dll with some interface which do all the job. Now I want to call this DLL from the NT indicator code. Here how I'm doing it:
    Code:
    [DllImport("DarkMindConnect.dll")]
            public static extern int	DarkMindInit([MarshalAs(UnmanagedType.LPStr)]string host, [MarshalAs(UnmanagedType.LPStr)]string accountKey, [MarshalAs(UnmanagedType.LPStr)]string folder);
    		......
    protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                Overlay				= false;
    			
    			int result = DarkMindInit(Host, AccountKey, Folder);
    			Print("DarkMindInit: " + result);
            }
    My DLL file is placed in folder <My Docs>\NinjaTrader 7\bin\Custom\, all other DLLs this one depends on are also there. But when I'm adding indicator to a chart I'm getting an error in the output:
    Failed to call method 'Initialize' for indicator 'TestDSConnect': An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
    Could someone please help me: when it's says "Incorrect format" - what does it refer to? Could it be the case because my DLL is build for x86 - not x64?
    Last edited by Globus000; 05-01-2016, 03:33 PM.

    #2
    Hello,

    Thank you for the question.

    While this is outside of the scope of what our NinjaScript team can really support, I can provide some items which could potentially help that you can check.

    This message specifically is thrown if you are using a incorrect format assembly based on the executing assemblies format. I.E. you have 64 bit NT open and have a DLL built for X86. Or the opposite, you have a X64 dll and are utilizing x86NT. Assemblies that are not written in C# specifically can run into this problem as you have to pick either 64, or 32 bit for the build.

    You noted this is X86, are you also using the 32 bit NinjaTrader? If not I would suggest leaving all code as is and try using the 32 bit icon first.

    If that does not work, is this a free item in which I could test a sample of the code you are using? If so that may assist in finding the answer.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse
      Thanks for your reply. As far as I understand NinjaTrader is based on .NET Framework and I presume it's version 3.5/ Probably my problem is because I have my assemblies built for 4.5.
      Actually what I would like to know - can I make my own indicator and use 3rd-party .NET assembly - for example I want to use ServiceStack client to connect to my webservice.

      Comment


        #4
        Hello,

        Thank you for the reply.

        NinjaTrader 7 is .net 3.5, NinjaTrader 8 would be 4.5 so that is likely the cause. You would need to re compile out to a 3.5 dll if possible to be able to reference the file in NT7.

        Regarding third party assemblies, the only limitation would be if you can get the assembly to load in Ninjatrader. Really all that means is that all its references are met and it is able to be executed. Outside of that you are free to use any .net assemblies so long as the versions of the assembly matches or is less than the version of ninjatraders .net. As long as the syntax you are using is correct for invoking the library it should work.

        One simple way to test an assembly would be first load it in NinjaTrader, use the suggested syntax to invoke the assembly, if it works you are all set otherwise if it does not you could try creating a console application in visual studio. In the console application, reference the third party assembly and do further testing there. You can limit down what the problem is if it is syntax related and get it to a working state. From there you can try to replicate what you needed to do in NInjaTrader to get it to work.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by saeed, Today, 12:32 PM
        3 responses
        27 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by motog4, Today, 11:42 AM
        3 responses
        16 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by derivtrader, Today, 11:20 AM
        5 responses
        27 views
        0 likes
        Last Post derivtrader  
        Started by TAJTrades, Today, 10:34 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by timcjpfx, Today, 10:20 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X