Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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;
    			
    			[B]int result = DarkMindInit(Host, AccountKey, Folder);[/B]
    			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 Christopher_R, Today, 12:29 AM
        0 responses
        9 views
        0 likes
        Last Post Christopher_R  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        166 responses
        2,235 views
        0 likes
        Last Post sidlercom80  
        Started by thread, Yesterday, 11:58 PM
        0 responses
        3 views
        0 likes
        Last Post thread
        by thread
         
        Started by jclose, Yesterday, 09:37 PM
        0 responses
        8 views
        0 likes
        Last Post jclose
        by jclose
         
        Started by WeyldFalcon, 08-07-2020, 06:13 AM
        10 responses
        1,415 views
        0 likes
        Last Post Traderontheroad  
        Working...
        X