Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

C++ DLL not found in c# Indicator

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

    C++ DLL not found in c# Indicator

    I'm developing a C++ DLL to be called by an Indicator I am also developing in c# in NT8. No matter where I place the DLL (/bin/Custom or the c# Indicator subfolder), I get the message Indicator 'NTTestMyDLL': Error on calling 'OnStateChange' method: Unable to load DLL 'NTTest.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E). I tested the DLL call from simple c# console applications using both NET 3.5 and NET 4.0 and both work. Years ago, I developed a DLL using Java for NT7 and it worked. What is going on? I'll furnish any sample code required to help solve this problem, including the console applications, which are extremely short.

    #2
    Hello trubolotta,

    Is the dll in Documents\NinjaTrader 8\bin\Custom?

    Do you have a reference to the file in that location?
    https://ninjatrader.com/support/help...indicators.htm

    Is there a using statement to the namespace->class from the dll in the indicator?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes, the dll is in the right Custom folder.

      If I add a reference to the dll, I get a compile error CS0009 (Metadata file .... could not be opened. ... incorrect format).

      There is no using statement since the dll does not use a namespace and does not use a class. It simply exports four trivial functions for testing. I just now declared a namespace ("NT8DLL), added a using statement to my c# indicator, but that also throws an error.

      Comment


        #4
        Hello trubolotta,

        While this is outside of what is supported by NinjaTrader Support, I was able to find an example posted by a previous support tech. This code is 100% unsupported.
        https://ninjatrader.com/support/foru...300#post777300
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I have read everything linked before but to no avail. user32.dll is a system ddl so I'm not surprised it loads from memory. I'm going to post the code in the hope that another developer may have solved the problem. It's very simple dll that runs in a c# console application but not in NT8. That is what is so baffling. This is related to a custom indicator I'm developing for my son, who is a licensed vendor and intends to distribute licensed copies of the indicator. The C++ dll would be imported into the ../Custom folder, where I have placed it for testing. I have made a related post concerning the security offered by Agile.NET and decided it was inadequate to protect the core algorithms of the custom indicator, hence the use of a C++ dll.

          The NTTest.h header file:
          #pragma once
          extern "C" __declspec(dllexport) int Add_ints(int a, int b);

          The NTTest cpp file:
          #include "pch.h"
          #include "NTTest.h"
          extern int Add_ints(int a, int b)
          {
          return a + b;
          };

          The c# console file:
          using System;
          using System.Runtime.InteropServices;
          namespace ConsoleNTTestDLL4_0
          {
          class Program
          {
          [DllImport("NTTest.dll", CallingConvention = CallingConvention.Cdecl)]
          public static extern int Add_ints(int a, int b);

          static void Main(string[] args)
          {
          Console.WriteLine("This is C# program");
          Console.WriteLine(Add_ints(5, 3));
          Console.ReadKey(true);
          }
          }
          }

          The Indicator MyDLLTest.cs is the minimal code generated by NT8 except for the following:
          public class MyDLLTest : Indicator
          {
          [DllImport("NTTest.dll", CallingConvention = CallingConvention.Cdecl)]
          public static extern int Add_ints(int a, int b);
          ...

          and
          ...
          else if (State == State.DataLoaded)
          {
          int a = 5;
          int b = 3;
          int c = Add_ints(a, b);
          }
          ...

          Actually, it doesn't matter where I put Add_ints, it produces the same file not found error.

          Has anyone been able to use a C/C++ dll in NT8 - anywhere?
          Last edited by trubolotta; 08-01-2020, 09:19 AM.

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hello trubolotta,

            While this is outside of what is supported by NinjaTrader Support, I was able to find an example posted by a previous support tech. This code is 100% unsupported.
            https://ninjatrader.com/support/foru...300#post777300
            I must respectfully disagree with this. NT8 implements c# as NinjaScript. I would expect anything that works in c# should also work in NinjaScript, but it doesn't. I suspect no one knows why and perhaps this should be on a bug list.

            Comment


              #7
              Hello trubolotta,

              The NinjaTrader Support staff does not support all of C# or C++.

              We support the NinjaScript methods documented in the help guide. This not documented in the help guide or supported by the NinjaTrader Support team.

              This thread will remain open for any community members that may know unsupported steps to achieve this.

              You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ct, Today, 01:53 AM
              0 responses
              4 views
              0 likes
              Last Post ct
              by ct
               
              Started by SmartArtsStudio, Yesterday, 11:24 PM
              0 responses
              3 views
              0 likes
              Last Post SmartArtsStudio  
              Started by kenz987, Yesterday, 10:06 PM
              0 responses
              4 views
              0 likes
              Last Post kenz987
              by kenz987
               
              Started by AaronKoRn, Yesterday, 07:24 PM
              0 responses
              8 views
              0 likes
              Last Post AaronKoRn  
              Started by Aquatrade, 05-15-2021, 11:46 AM
              1 response
              17 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X