简体   繁体   中英

Access .net DLL from Java

I am new to java and DLL-s

I need to access DLL's methods from java . So go easy on me.

I have tried using JNA to access the DLL here is what I have done.

import com.sun.jna.Library;

public class mapper {

  public interface mtApi extends Library {
        public boolean IsStopped();
  }

  public static void main(String []args){
     mtApi lib = (mtApi) Native.loadLibrary("MtApi", mtApi.class);
     boolean test = lib.IsStopped();
     System.out.println(test);

  }
}

When I run the code, I am getting the following error:

Exception in thread "main" java.lang.UnsatisfiedLinkError:
Error looking up function 'IsStopped':
The specified procedure could not be found.

I understand that this error is saying it cannot find the function, but I have no idea how to fix it.

I am trying to use this API mt4api

and here is the method, I am attempting to access MQL4

Can anyone tell me what I am doing wrong?

I have looked at other alternatives, like jni4net , but I cannot get this working either.

If anyone can link me to a tutorial that shows me how to set this up, or knows how to, I would be greatfull.

Trading?
Hunting for milliseconds to shave-off?
Go rather into Distributed Processing... Definitely safer than relying on API !

While your OP was directed onto how bend java to call .NET DLL-functions, let me sketch a much future-safer solution .

Using AI/ML-regression based predictors for FOREX trading, I was hunting in the same forest. The best solution found within the last about 12-years, having spent about a few hundreds man*years of experience, was setup in the following manner:

Host A executes trades: operates MetaTrader Terminal 4, with both Script and EA --- the distributed-processing system communicates with with a use of ZeroMQ low-latency messaging/signalling framework ( about a few tens of microseconds needed )

Host B executes AI/ML processing of predictions for a traded instrument ( about a few hundreds of microseconds apply )

Cluster C executes continuous AI/ML predictor re-trainings and HyperParameterSPACE model selections ( many CPU-hours indeed needed, continuous model self-adapting process running 24/7 )


Signalling / Messaging layer with ZeroMQ has ports and/or bindings available and ready for most of the mainstream and many of niche programming languages, including java .

Hidden dangers of going just against a published API:

While the efforts for system integration and testing are immense, the API specifications are always dangerous for specification creeping.

This said, add countless man*months consumed on debugging after a silent change in MT4 language specifications that de-rail your previous tools + libraries. Why? Just imagine. Some time ago, MQL4 stopped to be MQL4 and was silently shifted towards MQL5 , under a name New - MQL4 . Among other changes in compilation, there were many small and big nails in the coffin -- string surprisingly ceased to be a string and was hidden as an internal struct -- which one could guess what will cause with all DLL-calls.

So, beware of API creepings.


Does it hurt a distributed processing solution?

No.

With a wise message-layout design, there are no adverse effects of MetaTrader Terminal 4 behaviour and all the logic ( incl. the strategy decision ) is put outside this creeping platform.

Doable. Fast and smart. Also could use remote-GPU-cluster processing, if your budget allows.


Does it work even in Strategy Tester?

Yes, it does.

If anyone has the gut to rely on the in-built Strategy Tester, the distributed-processing model still works there. Performance depends on the preferred style of modelling, a full one year, tick-by-tick simulation, with a quite complex AI/ML components took a few days on a common COTS desktops PC-systems ( after years of Quant R&D, we do not use Strategy Tester internally at all, but the request was to batch-test the y/y tick-data, so could be commented here ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM