C++ to call managed .Net dll

Ninjatrader.com provides a dll (NinjaTrader.Client.dll) along with their trading platform which allows third party API's to send orders (among other things) to their trading platform. The dll is a managed .Net dll. Here is a typical function:
int Ask(string instrument, double price, int size)
Sets the ask price and size for the specified instrument. A return value of 0 indicates success and -1 indicates an error.

What would the code in a C++ dll look like which would call that function and return its value to another application. Never mind what the other application has to do to communicate with the C++ dll.All I can tell you about the other application is that it can only communicate with dll's that use the __stdcall calling convention.
This has already been answered here:
https://cplusplus.com/forum/general/285501/#msg1240201

The example shows you the basic idea. Should be relatively easy to adapt for your "NinjaTrader.Client.dll" or whatever "managed" DLL.

If you want __stdcall calling convention for the functions exported from your "wrapper" DLL, just add the keyword to the declaration!
https://learn.microsoft.com/en-us/cpp/cpp/stdcall?view=msvc-170

(Be aware that __stdcall is used with Win32 API functions, but it is not usually used for anything else)
Last edited on
Neither this
WRAPPERLIBRARY_API wchart_t __stdcall MySayHelloWrapper(void);
nor this
WRAPPERLIBRARY_API wchart_t __stdcall MySayHelloWrapper(wchar_t *parameter);

resulted in a good build.

Topic archived. No new replies allowed.