C++ Exception

I run two applications, Tradestation and Ninjatrader. Ninjatrader provides a managed .Net dll to allow other applications to communicate with it. We built a second dll to allow Tradestation to use the Ninjatrader dll. Using the dll on a Win 11 desktop with the Ninjatrader version 8.0.27 and lower, it works as intended. Using the dll on Windows server 2019, the dll works as expected with Ninjatrader 8.0.28. However, on a Windows 11 desktop, it return C++ exception trying to use it with Ninjatrader version 8.0.28. Can someone give me a hint on where to look for the problem?
did you eliminate the obvious things like permissions (run as admin to test it) or folder paths (trying to reach illegal path due to windows changing system paths sometimes) etc?
have you searched the problem online? I did very briefly and windows updates caused havoc a few months back, so make sure the machine is fully up to date.
anything more in the windows crash logs etc?
is the dll in the path that the using program can get to it?
basic stuff, but all easy to overlook.
What is the exact C++ exception you are getting?

Did you rule out any dependency issues, using a tool like Dependencies?
https://github.com/lucasg/Dependencies
Here is the setup. This was working on my desktop at first, but no longer does. It still works on the server. If I copy the dll from the server to my desktop, then it still does not work. The dll that is on the server was created on my desktop a few days ago. All I know is what the Tradestation app reports, which is C++ exception. I recently updatd Windows on my desktop, but only because the dll had stopped working by then. I have the VS project that was given to me by the developer, so I can recreate the dll. Both DLL's are in the Tradestation program folder which is "C:\Program Files (x86)\TradeStation 10.0\Program". Tradestation is 32 bit, Ninjatrader is 64 bit. Another weird thing is that when it was working on my desktop, it quit working when I updated Ninjatrder to a later version, but when I roll back Ninjatrader to the version that it was working with, it still does not work. I do not understand much about dependencies or figuring out if that is the problem.
https://imgur.com/a/12LFOYQ

Further information: On another Win 11 computer I have three versions of the dll, all created using the same VS project, and they all work. I have three Win 11 machines. On two of them, the dll does not work, They are OS build 22621.1848 and 22621.1928. The OS build on the machine that is working is 22621.1778. Does this suggest that it is a Windows issue?
Last edited on
Still the most important question remains: What exact exception do you get, and where?

Do you get an exception in "Tradestation" when trying to call the C++ DLL, or do you get an exception inside your C++ DLL when trying to call the managed DLL, or is the exception thrown inside the managed DLL ???

And, once again, did you rule out any dependency issues, by using a tool like Dependencies?
https://github.com/lucasg/Dependencies

If you replace "Tradestation" with your own minimal "Demo" program, which does nothing but calling your C++ DLL, does it work?

Instead of speculating you probably should try to narrow down the problem...

________

You could try something like this in your "wrapper" DLL:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using namespace System::Windows::Forms;

static int CallManagedDll(void);

int MyDllEntryPoint(void) // <-- will be called by the application
{
    __try
    {
        MessageBox::Show("Hello from Wrapper DLL!");
        return CallManagedDll();
    }
    __except (1)
    {
        MessageBox::Show("Structured exception in Wrapper DLL !!!");
        return -1;
    }
}

static int CallManagedDll(void)
{
    try
    {
        /* CALL MANAGED DLL HERE !!! */
    }
    catch (...)
    {
        MessageBox::Show("C++ exception in Wrapper DLL !!!");
        return -1;
    }
}
Last edited on
I do not know if the exception comes from within the wrapper dll, or Easylanguage.
I will try your suggestion on the messagebox.

The dependencies tool is somewhat beyond my ken, but I'll study it.
The dependencies tool is somewhat beyond my ken, but I'll study it.

It simply shows which DLL's your EXE or DLL depends on. Not only direct dependencies, but also transitive ones!

Also, this tool would show you if a required DLL is missing, or if a required entry point (function) is missing from one of the required DLL's.

It is essential to know your dependencies, if you plan to deploy your software on another machine...
Last edited on
My situation has been partially resolved by running regasm for the dll of interest, meaning this:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe "C:\Program Files\NinjaTrader 8\bin\NinjaTrader.Client.dll" /codebase

And while this got one of my computers to work with the wrapper dll, on another Windows 11 computer, it fails.

Each machine if running the same version of the apps I'm working with.

Why would this be hit and miss?

The developer I'm working with has created a stand alone app for testing the Ninjatrader.dll. I can run it from a command window and tests the ability to use the Ninjatrader dll (NinjaTrader.Client.dll). It works sometimes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
namespace DirectNt8ApiCaller {
    internal class DotNetStartPoint {
        static void Main(string[] args) {
            NinjaTrader.Client.Client m_Nt8ApiClient = new NinjaTrader.Client.Client();


            string v_sAccountId = "Sim101";
            int v_dConnectedRes = m_Nt8ApiClient.Connected(1);



            System.Diagnostics.Debug.WriteLine(".Connected(0) returned " + v_dConnectedRes);
            long v_dPosition = m_Nt8ApiClient.MarketPosition("ES SEP23", v_sAccountId);
            System.Diagnostics.Debug.WriteLine(".MarketPosition returned " + v_dPosition);

            double a_fCashValue = m_Nt8ApiClient.CashValue(v_sAccountId);
            System.Diagnostics.Debug.WriteLine(".MarketPosition returned " + a_fCashValue);

            m_Nt8ApiClient.TearDown();
        }
 
    }
}
Last edited on
I think we finally have come to an end. The last problem was just some vestigial DLL keys that had to be deleted before it would all work.

Thanks for helping.
Topic archived. No new replies allowed.