Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Q for advanced programmer re DLLs
Collapse
X
-
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
-
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
-
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
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by LawrenHom, Today, 10:45 PM
|
0 responses
3 views
0 likes
|
Last Post
by LawrenHom
Today, 10:45 PM
|
||
Started by love2code2trade, Yesterday, 01:45 PM
|
4 responses
28 views
0 likes
|
Last Post Today, 10:31 PM | ||
Started by funk10101, Today, 09:43 PM
|
0 responses
7 views
0 likes
|
Last Post
by funk10101
Today, 09:43 PM
|
||
Started by pkefal, 04-11-2024, 07:39 AM
|
11 responses
37 views
0 likes
|
Last Post
by jeronymite
Today, 09:37 PM
|
||
Started by bill2023, Yesterday, 08:51 AM
|
8 responses
44 views
0 likes
|
Last Post
by bill2023
Today, 09:27 PM
|
Comment