Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Load NTDirect.dll from C++ library.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Load NTDirect.dll from C++ library.

    Hello.

    I try load NTDirect.dll from C# like this:
    Code:
    [DllImport("NTDirect.dll")]
    public static extern int Last(string instrument, double price, int size);
    and it work fine. How can i use NTDirect.dll from my C++ dll?
    I try this code:
    Code:
    typedef int(*last_func)(const char* instrument, double price, int size);
    typedef int(*conn_func)(int show_message);
    
    HMODULE nt_lib;
    last_func Last;
    conn_func Connected;
    
    
    BOOL APIENTRY DllMain(HANDLE hModule, DWORD  fdwReason, LPVOID lpReserved)
    {
    	char err_msg[10];
    
    	switch (fdwReason)
    	{
    	case DLL_PROCESS_ATTACH: // Подключение DLL          
    		nt_lib = LoadLibrary("NTDirect.dll");
    
    		if (!nt_lib) {
    			OutputDebugString("could not load the dynamic library");
    
    			sprintf_s(err_msg, "%d", GetLastError());
    			OutputDebugString(err_msg);
    
    			return FALSE;
    		}
    
    		//# resolve function address here
    		Last = (last_func)GetProcAddress(nt_lib, "Last");
    		if (!Last) {
    			OutputDebugString("could not locate the function");
    
    			sprintf_s(err_msg, "%d", GetLastError());
    			OutputDebugString(err_msg);
    
    			return FALSE;
    		}
    
    		//# resolve function address here
    		Connected = (conn_func)GetProcAddress(nt_lib, "Connected");
    		if (!Connected) {
    			OutputDebugString("could not locate the function");
    
    			sprintf_s(err_msg, "%d", GetLastError());
    			OutputDebugString(err_msg);
    
    			return FALSE;
    		}
    
    		break;
    	case DLL_PROCESS_DETACH: // Отключение DLL
    		break;
    	case DLL_THREAD_ATTACH:  // Создание нового потока
    		break;
    	case DLL_THREAD_DETACH:  // Завершение потока
    		break;
    	}
    	return TRUE;
    }
    ....
    const char* instr = "TEST";
    Last(instr, 200, 100);
    and it's not working.

    I have this error:
    Code:
    Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

    #2
    Hello Dzammer,

    Thank you for writing in. Unfortunately this is not supported. This thread will remain open in case any other users may be able to further assist.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      After reinstalling platform, this code worked fine, thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by gemify, 11-11-2022, 11:52 AM
      6 responses
      803 views
      2 likes
      Last Post ultls
      by ultls
       
      Started by ScottWalsh, Today, 04:52 PM
      0 responses
      3 views
      0 likes
      Last Post ScottWalsh  
      Started by ScottWalsh, Today, 04:29 PM
      0 responses
      7 views
      0 likes
      Last Post ScottWalsh  
      Started by rtwave, 04-12-2024, 09:30 AM
      2 responses
      22 views
      0 likes
      Last Post rtwave
      by rtwave
       
      Started by tsantospinto, 04-12-2024, 07:04 PM
      5 responses
      70 views
      0 likes
      Last Post tsantospinto  
      Working...
      X