I tried the following code in Visual C# 2010 Beta 2 on Win7Pro64. When I first
tried to add the references for JDLLServerLib and JEXEServerLib, I noticed that
the non-64 bit versions were listed in the Add Reference COM browser. I ran
jreg.bat from j64-602\bin. The code built and ran successfully with this
result:
>J DLL Test.exe"
J DoR ended with status 0 and result
1 1 1 1
0 1 0 1
0 0 1 1
0 0 0 1
===
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JDLLServerLib;
using JEXEServerLib;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// JDLLServerClass j = new JDLLServerClass();
JDLLServer j = new JDLLServer();
object result;
int status = j.DoR("2| !/~i.4", out result);
System.Console.WriteLine(string.Format("J DoR ended with status
{0}
and result\n{1}", status, result));
}
}
}
--
David Mitchell
On 12/15/2009 11:19, Matthew Brand wrote:
> I have done some investigations (outside of NinjaTrader, just using
> Visual Studio c#). I do not know for sure, but it might be that the
> JDLLServerClass does not work on 64 bit Windows 7? I am in way over my
> head here, I have no idea what is going on - so apologies in advance
> if I am wrong.
>
> I read this:
> http://blogs.msdn.com/mshneer/archive/2009/12/07/interop-type-xxx-cannot-be-embedded-use-the-applicable-interface-instead.aspx
>
> So I removed the "Class" prefix from "JDLLServerClass" to end up with
> a program that looks like this:
>
> using System;
> using System.Collections.Generic;
> using System.Linq;
> using System.Text;
> using JDLLServerLib;
> using JEXEServerLib;
>
> namespace ConsoleApplication1
> {
> class Program
> {
> static void Main(string[] args)
> {
> // JDLLServerClass j = new JDLLServerClass();
> JDLLServer j = new JDLLServer();
> object result;
> int status = j.DoR("2| !/~i.4", out result);
> string.Format("J DoR ended with status {0} and
> result\n{1}", status, result);
>
> }
> }
> }
>
>
> But now I get a different error:
>
> System.Runtime.InteropServices.COMException was unhandled
> Message=Retrieving the COM class factory for component with CLSID
> {21EB05EA-1AB3-11CF-A2AC-8FF70874C460} failed due to the following
> error: 80040154 Class not registered (Exception from HRESULT:
> 0x80040154 (REGDB_E_CLASSNOTREG)).
> Source=mscorlib
> ErrorCode=-2147221164
> StackTrace:
> at System.RuntimeTypeHandle.CreateInstance(RuntimeType type,
> Boolean publicOnly, Boolean noCheck, Boolean& canBeCached,
> RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
> at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,
> Boolean skipCheckThis, Boolean fillCache)
> at System.RuntimeType.CreateInstanceDefaultCtor(Boolean
> publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis,
> Boolean fillCache)
> at System.Activator.CreateInstance(Type type, Boolean nonPublic)
> at System.Activator.CreateInstance(Type type)
> at ConsoleApplication1.Program.Main(String[] args) in
> c:\users\mtthwbrnd\documents\visual studio
> 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line
> 15
> at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,
> String[] args)
> at System.AppDomain.ExecuteAssembly(String assemblyFile,
> Evidence assemblySecurity, String[] args)
> at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
> at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
> at System.Threading.ExecutionContext.Run(ExecutionContext
> executionContext, ContextCallback callback, Object state, Boolean
> ignoreSyncCtx)
> at System.Threading.ExecutionContext.Run(ExecutionContext
> executionContext, ContextCallback callback, Object state)
> at System.Threading.ThreadHelper.ThreadStart()
> InnerException:
>
> This might be relevent?:
>
> "PROBLEM:
>
> When you run the .net Code in X64 Environment you will get the
> following error message.
>
> " Failed --Retrieving the COM class factory for component with CLSID ...."
>
> E.g. in CMS Export / Import server side .net code =
> "ExportSiteContentIncremental(...) Failed --Retrieving the COM class
> factory for component with CLSID
> {CA0752B3-021C-4F99-82E3-2C0F19C5E953} failed due to the following
> error: 80040154."
>
> WORKAROUND:
>
> The possible workaround is modify your project's platform from 'Any
> CPU' to 'X86' (in Project's Properties, Build/Platform's Target)
>
> ROOTCAUSE
>
> The VSS Interop is a managed assembly using 32-bit Framework and the
> dll contains a 32-bit COM object. If you run this COM dll in 64 bit
> environment, you will get the error message.
> "
> http://blogs.msdn.com/karthick/archive/2006/02/28/540780.aspx
>
> Only problem for me here is that my visual studio only has the "x86" option.
>
>
>
>
> 2009/12/14 Matthew Brand<[email protected]>:
>> I just got a response from the NinjaTrader supoport team on their
>> forum to asking:
>> "Best course of action would be to inquiry with the author to see if
>> they can direct you to where it needs to be dropped."
>>
>> http://www.ninjatrader-support2.com/vb/showthread.php?p=133247#post133247
>>
>> Is there a special place that the dll needs to be put?
>>
>> 2009/12/14 Matthew Brand<[email protected]>:
>>> I have added the DLL as a reference in the C# program with:
>>>
>>> right clik (in the C# IDE)->references...->add->(navigate to
>>> Interop.JDLLServerLib.dll)
>>>
>>> and have the lines:
>>>
>>> using JDLLServerLib;
>>>
>>> and
>>>
>>> JDLLServerClass j = new JDLLServerClass();
>>>
>>> in my c# program. The intellisense recognises all of the things that
>>> are inside JDLLServerClass ... which to me inidicates that the DLL
>>> file was found correctly. But when I run the program I get the error:
>>>
>>> 14/12/2009 13:02:34,Strategy,Error on calling 'OnBarUpdate' method for
>>> strategy 'JayServerExample': Could not load file or assembly
>>> 'Interop.JDLLServerLib, Version=3.0.0.0, Culture=neutral,
>>> PublicKeyToken=null' or one of its dependencies. The system cannot
>>> find the file specified.,
>>>
>>> It's a long shot becuase it is nothing to do with J, but does anybody
>>> have any ideas what I might need to do? [PS, I have only used C# since
>>> last week so really don't quite "get it" at this stage!]
>>>
>>> Thanks,
>>> Matthew.
>>>
>>>
>>> For reference, the c# program is:
>>>
>>> #region Using declarations
>>> using System;
>>> using System.ComponentModel;
>>> using System.Diagnostics;
>>> using System.Drawing;
>>> using System.Drawing.Drawing2D;
>>> using System.Xml.Serialization;
>>> using NinjaTrader.Cbi;
>>> using NinjaTrader.Data;
>>> using NinjaTrader.Indicator;
>>> using NinjaTrader.Gui.Chart;
>>> using NinjaTrader.Strategy;
>>>
>>> using JDLLServerLib;
>>>
>>> #endregion
>>>
>>> // This namespace holds all strategies and is required. Do not change it.
>>> namespace NinjaTrader.Strategy
>>> {
>>> ///<summary>
>>> /// Example of communcation with J
>>> ///</summary>
>>> [Description("Example of communcation with J")]
>>> public class JayServerExample : Strategy
>>> {
>>> #region Variables
>>> // Wizard generated variables
>>> // User defined variables (add any user defined variables below)
>>> #endregion
>>>
>>> ///<summary>
>>> /// This method is used to configure the strategy and is
>>> called once before any strategy method is called.
>>> ///</summary>
>>> protected override void Initialize()
>>> {
>>> CalculateOnBarClose = true;
>>> }
>>>
>>> ///<summary>
>>> /// Called on each bar update event (incoming tick)
>>> ///</summary>
>>> protected override void OnBarUpdate()
>>> {
>>> Print(Bars.Count);
>>> JDLLServerClass j = new JDLLServerClass();
>>> }
>>>
>>> #region Properties
>>> #endregion
>>> }
>>> }
>>>
>>>
>>> 2009/12/12 Matthew Brand<[email protected]>:
>>>> That did it, thanks :-).
>>>>
>>>> PS. For anyone else with this problem, if you get a domain error when
>>>> you run the command:
>>>> wd 'exec *',BINPATH,'\jreg.bat'
>>>>
>>>> it might be that you need to run as administrator in which case execute:
>>>> BINPATH,'\jreg.bat'
>>>>
>>>> to see where the file is and go to it in windows explorer, right click
>>>> and select run as administrator.
>>>>
>>>> 2009/12/12 Dan Bron<[email protected]>:
>>>>> Matthew wrote:
>>>>>> But the JDLLServer does not appear on the COM tab for me. Is there
>>>>>> something I need to install first?
>>>>>
>>>>> Try running wd 'exec *',BINPATH,'\jreg.bat' . Or just double-click
>>>>> that
>>>>> batch file in Windows explorer.
>>>>>
>>>>> -Dan
>>>>>
>>>>> ----------------------------------------------------------------------
>>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>>
>>>>
>>>
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm