COM library Initialization failed with code 0x80010106 in C #

I tried to manually transfer data to NT using C #, but I got the error: "Failed to initialize COM library (0x80010106)." I have already added the link 'Ninjatrader.Client.dll' I am posting my code as shown below:

using System;
using System.Runtime.InteropServices;
using System.Threading; 
using System.Diagnostics;

namespace read_file
{
 public static class Program
 {
    [DllImport("NtDirect.dll", EntryPoint = "Connected", SetLastError = true)]
    public extern static int Connected(int showMessage);

    [DllImport("NtDirect.dll", SetLastError = true)]
    public static extern int Last(string instrument, double price, int size);

    public static void Main(string[] args)
    {
        NinjaTrader.Client.Client NTClient = new NinjaTrader.Client.Client();
        int ConnectStatus = Connected(1);

        NTClient.Command("PLACE", "Sim101", "ES 03-08", "BUY", 1, "LIMIT", 1245.00, 0,   "GTC", "ax1234", "", "", "");
        int k;
        for (int i = 0; i < 100; i++)
        {
            k = 10 * (i + 1);
            Last("AUDUSD", k, 4);
            for (int j = 0; j < 999999999; j++)
            {
            }
            Console.WriteLine(k);
                        }

        }
    }
 }

please tell me the correct offer. thank

+5
source share
3 answers

From the header file WinError.h SDK:

//
// MessageId: RPC_E_CHANGED_MODE
//
// MessageText:
//
// Cannot change thread mode after it is set.
//
#define RPC_E_CHANGED_MODE               _HRESULT_TYPEDEF_(0x80010106L)

DLL, . DLL CoInitializeEx() , . , . , , , DLL, CoInitializeEx() .

  • , Main(). [STAThread] [MTAThread], , DLL. , , [STAThread], COM-, STA.

  • , , thread SetApartmentState() , .

  • threadpool, , BackgroundWorker Task, BeginInvoke QueueUserWorkItem(), , MTA. Thread , . .

. DLL STA (), Application.Run(). , , , , .

+10

[STAThread] Program.

, , COM-, STA (Single Thread Apartment), STAThreadAttribute .

STAThreadAttribute...

+1

.
, COM Factory .

, , :

  • .
  • Windows Server 2008R2 -

, : , NinjaTrader...
EventLogs Application...

, ..

0

All Articles