Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Q for advanced programmer re DLLs

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

    Q for advanced programmer re DLLs

    Would one of you advanced programmers show me an example of how to call a DLL (preferably User32 or Kernel) from a NT indicator? Thanks, Ken.

    #2
    MsgBox works

    The following code works as is - seems if I place a Reference to user32 it stops working.
    //================================================== ==
    #region Using declarations
    using System;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.ComponentModel;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    using System.Runtime.InteropServices;
    using System.Text;
    #endregion
    //
    //
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    public class call_msg
    {
    [DllImport("User32.dll", EntryPoint="MessageBox", CharSet=CharSet.Auto)]
    public static extern int MsgBox(int hWnd, String text, String caption, uint type);
    }
    /// <summary>
    /// zTestMsgBox
    /// </summary>
    [Description("zTestMsgBox")]
    public class zTestMsgBox : Indicator
    {
    #region Variables
    // User defined variables (add any user defined variables below)
    string sData = "Hello World";
    #endregion


    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "Plot0"));
    CalculateOnBarClose = true;
    Overlay = false;
    PriceTypeSupported = false;
    PaintPriceMarkers = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if(CurrentBar > 0) return;
    call_msg.MsgBox(0, sData, "PInvoke Sample", 0);
    }

    #region Properties
    ...
    .#endregion

    Comment


      #3
      Thanks for posting your code and findings Ken. I am sure someone will benefit from it.

      I think I mentioned this before in another thread, but if not here it is again. Since this is not a supported item, we will not be able to assist in this endeavor. Good luck though.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Error

        Error - Trying to read or write protected memory.
        Got same message on other calls.
        Well, yes, I am trying to read memory - I want to get certain data from inside the kernel, but it should be allowed.
        ANYONE have a solution for this... PLEASE???
        //==============================================
        #region Using declarations
        using System;
        using System.Diagnostics;
        using System.Drawing;
        using System.Drawing.Drawing2D;
        using System.ComponentModel;
        using System.Xml.Serialization;
        using NinjaTrader.Cbi;
        using NinjaTrader.Data;
        using NinjaTrader.Gui.Chart;
        using System.Runtime.InteropServices;
        using System.Text;
        #endregion
        //
        //
        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
        public class call_k32
        {
        [DllImport("kernel32.dll", EntryPoint="GetComputerNameA")]
        public static extern long GetCompName(StringBuilder buf, long lLgth);
        // this compiled, gives error trying to read protected memory
        }

        /// <summary>
        /// zTestGetCompName
        /// </summary>
        [Description("zTestGetCompName")]
        public class zTestGetCompName : Indicator
        {
        #region Variables
        // User defined variables (add any user defined variables below)
        long lRtn = 0;
        long lBufLgth = 0;
        #endregion


        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
        Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "Plot0"));
        CalculateOnBarClose = true;
        Overlay = false;
        PriceTypeSupported = false;
        PaintPriceMarkers = false;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
        if(CurrentBar > 0) return;
        StringBuilder sb = new StringBuilder(256);
        lBufLgth = sb.Capacity;
        lRtn = call_k32.GetCompName(sb, lBufLgth);
        }

        ... etc

        Comment


          #5
          Josh

          This is no different in concept than StreamWriter and other items that you folks have provided examples for.

          Comment


            #6
            Ken,

            It is outside the scope of what we offer support for. This is C# and it is impossible for us to support all aspects of C# here. Thank you for understanding.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Have a look at http://msdn.microsoft.com/en-us/libr...8VS.71%29.aspx

              Comment


                #8
                Hi, I have a similar question regarding DLLs and indicators but in the inverse way.

                Is there any way to call Ninja Indicators from DLL functions provided through the ATI ?

                Your advise is highly appreciated.

                Thank you.

                Comment


                  #9
                  hana_maui, it is not possible to call indicators from the ATI .dll.
                  AustinNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by LawrenHom, Today, 10:45 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post LawrenHom  
                  Started by love2code2trade, Yesterday, 01:45 PM
                  4 responses
                  28 views
                  0 likes
                  Last Post love2code2trade  
                  Started by funk10101, Today, 09:43 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post funk10101  
                  Started by pkefal, 04-11-2024, 07:39 AM
                  11 responses
                  37 views
                  0 likes
                  Last Post jeronymite  
                  Started by bill2023, Yesterday, 08:51 AM
                  8 responses
                  44 views
                  0 likes
                  Last Post bill2023  
                  Working...
                  X