Hi Matthew,

I asked the team leader for the project I mentioned and they actually solved it 
two ways:
1. As suggested, compiled the solution with platform set to x86 instead of 
AllCPU.
2. Went back to some of the 3rd party suppliers and got versions for the 64bit 
OS. Actually, with this, they eliminated the use of Interopt's.

I'm a bit embarrassed that my reply is not very useful to your problem. 

r/Alex

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Matthew Brand
Sent: Wednesday, December 16, 2009 4:45 PM
To: Programming forum
Subject: Re: [Jprogramming] C# .NET COM JDLLServer

Hi Alex,

> Just saw this thread (and the previous ones) ... unfortunately I'm at home 
> right now and the machine here is configured for gaming so theres no 
> development tools whatsoever installed. I'll be back in the office tomorrow 
> though and will give your problem a run through.
>
> The only caveat is that my dev machine is WindowsXP Pro 32bit so I may not 
> hit your problem since when I read your earlier code ... the only reason it 
> would have failed is if J.DLL wasn't registered properly which you have done 
> so correctly.
>
> Although I have been to some dev discussions at the office where they 
> mentioned the an Interopt problem when there was a deployment to a 64bit 
> machine, I'll guess I'll have to ask them how they worked around it.


Thanks, much appreciated ... I am stumped. :-).

>
> I know its a long shot but can you give JEXEServer a try instead of JDLL? I 
> believe it would still throw the same error though but its a curiosity.

Your EXE suggestion worked. In Visual Studio using EXE server works,
but using DLL does not. So I thought my problem was solved, but
alas...

The NinjaTrader C# IDE does not seem to allow references to EXE, only
to DLL! I will ask them about it on their forum. I will try to make
visual studio project to output a DLL containing a pass-through to the
J EXE, which hopefully I can call from NinjaTrader.

>
> Hmmm. I hope I don't offend you but are you using the 64bit version of J?

No offense taken, please feel free to suggest even the most basic
things. I know absolutely nothing about DLL's - apart from it appears
to be an incredibily complicated and delicate affair. I appreciate any
advice given.

Thanks,
Matthew.


>
> r/Alex
> ________________________________________
> From: [email protected] [[email protected]] 
> On Behalf Of Matthew Brand [[email protected]]
> Sent: Wednesday, December 16, 2009 12:19 AM
> To: Programming forum
> Subject: Re: [Jprogramming] C# .NET COM JDLLServer
>
> 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
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to