Help solve a problem with importing a function from a dll

 

I want to learn how to import functions from dll. I've tried different variants, but the following error keeps coming up: cannot call function from dll (error 127).

1. I tried compiling my project in C++ Builder 6.

2. same project in C++ Builder 2009.

3. I created a project from the DLLSample example in C++ Builder 2009, compiled it.

Same result everywhere: cannot call function from dll (error 127).

To test it, I use the script with PExpDll.dll - compiled library in C++ Builder 2009 from DLLSample example, that comes with MetaTrader 4.

Here is this script:

#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net//"

#import "PExpDll.dll"
int GetIntValue(int);
double GetDoubleValue(double);
string GetStringValue(string);
#import

//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
Print("Script start");
GetStringValue("I wonder if this will work?");
GetIntValue(10);

//----
return(0);
}
//+------------------------------------------------------------------+

Please help, tell me what I'm doing wrong...?

Thank you in advance.

 

Option 1) figure out where to put the def file. Without it, you probably won't get anywhere.

Option 2) install Visual Studio

 

LOL

option 3:

there are testers, at least from VB excel - check that the requested function is called.

If no - bad linker settings, yes - not an error in the MQL description

With the installation of MT4, a good C source DLL is delivered - use it for training, it will save a lot of time.

 
boysn >> :

#import "PExpDll.dll"
int GetIntValue(int);
double GetDoubleValue(double);
string GetStringValue(string);
#import

According to the rules of function declaration in MQL-4, you have a clear error:

int GetIntValue(int X);
double GetDoubleValue(double X);
string GetStringValue(string X);

There is no input parameter name, only type. This is not allowed in MQL-4.

 
Urain >> :

According to the rules of function declaration in MQL-4, there is a glaring error:

There is no input parameter name, only type. In MQL-4 it is not allowed.

What the compiler doesn't swear at, you can.

I tried writing it this way:

#import "timeService.dll"
// функция, выдающее смещение от Utc 
// до времени сервера и до локального времени
int timeService(
  string , //  <--- убрал имя переменной
  int & utcToServer[],
  int & utcToLocal[]  );
#import

Everything works fine.

Actually, according to C and C++ canons, you don't have to specify parameter names at all.

moreover, in most cases the programmer is busy sitting and commenting on them.

 

Thank you very much for your advice, thank you for responding.

1. In MT4 I have Service-Settings-Advisors-Confirm call of dll functions ticked. So, when I run script, it asks me if I should call such function...? I select "Yes" and then the following error comes: cannot call function from dll (error 127).

2. What about declarations of functions without parameters like double GetDoubleValue(double), it is written so in the samples, especially since the compiler doesn't complain about it, so it is ok.

3. But what about the def-file... Sure, maybe it's because of def-file, but I really don't know where to put it. In C++ Builder 6 and 2009 projects there are no such files with such an extension, i.e. when building the dll itself there seems to be nowhere to put it. In the same folder under the same name in \MetaTrader 4\experts\libraries folder is not the same... tried it... In short, it's not clear. Tried another example where a ready-made system dll is used

#import "kernel32.dll"
int _lopen (string path, int of);
int _lcreat (string path, int attrib);
int _llseek (int handle, int offset, int origin);
int _lread (int handle, string buffer, int bytes);
int _lwrite (int handle, string buffer, int bytes);
int _lclose (int handle);
#import

These functions are called. The reason for DLLSample is unclear.
If the reason is in the Linker, what can it be? I seem to be making the file standalone.

Uh... yeah... I don't get it. And the example in MT4 is sure to work? Has anyone checked it to see if it works?

Thank you all for responding and responding.

 
How do you pass it string parameters and give the result in the same type? Bilder has peculiarities when dealing with strings...
 
boysn >> :

{...} 3. As for the def file... Of course, maybe it's because of it, but it's really not clear where to put it. In C++ Builder 6 and 2009 projects there are no such files with this extension, i.e. when building the dll itself there seems to be nowhere to stick it. In the same folder under the same name in \MetaTrader 4\experts\libraries folder is not the same... tried it... In short, it's not clear. Tried another example that uses a ready-made system dll {...}

These functions are called... The reason for DLLSample is unclear.
If the reason is in the Linker, what could it be? I seem to be making the file standalone.

M...yeah...it's not clear. Is the example in MT4 sure it works? Has anyone tested it to see if it works?

Thank you all for responding and responding.

1) even though the builder is ahem... "slightly" wrong, def file is still needed

2) Have you tried to install Visual Studio yet?

3) example works. wrong builder.

 
jartmailru >> :

1) even though the builder is ahem... "slightly" wrong, def file is still needed

2) you haven't tried Visual Studio yet

3) example works. wrong builder.

i actually made dlls for mt4 on bilder, def-file wasn't useful...

 
boysn >> :

If Linker is the cause, what could be there? I seem to make the file standalone.


can you take a screenshot of the Compiler Linker and Packages tabs of the project settings?

 
alsu >> :

I used to make dlls for mt4 on dibilder, def-file was not useful...

Share an example with a colleague :-).

Maybe you need to write some squiggle before declaration of function there.

.

And bilder... I still have a copy of 6 with 4 service packs on it.

Stopped using it after a funny case :-).

When I add a function to a .cpp file, I get all sorts of glitches :-).

The glitches consisted in that the builder would lie about the parameters passed into the function through the stack.

You delete the function - everything is fine again.

I can also recall global variables which are accessible only from a module,

where they are declared, and from the rest you see rubbish :-).

Reason: