cannot load library MyLib.mq4' (error 193)

 

Can anyone advise me on this error?

I have built a set of common functions that I’m going to call in all my own indicators.

Instead of recoding each function in every indicator, I put them all in a Library and now I’m trying to import the library and the functions in the indicator.

It compiles successfully. But, as soon as I run the indicator on a chart, I get the error in the Expert Log (and the indicator won’t draw):

cannot load library MyLib.mq4' (error 193)

What I’ve already checked is:

. Tools/Options/Expert Advisors tab: The flag “Allow DLL imports” is checked to true.

. When I drop the indicator on the Chart and the property dialog appears, on the Common tab, the “Allow DLL imports” is checked to true.

.The #import statement is coded with the fully qualified path to the library:

#import "C:\Users\Ste\AppData\Local\VirtualStore\Program Files (x86)\MetaTrader\experts\libraries\SP_Lib.mq4"

int MyFunc(int value,int value2);

Any clue?

Thank you very much in advance.

Cheers

Stefano

 
It may well be a UAC issue, try installing MT4 in a directory other than Program Files, e.g. C:\MT4Installs\
 
RaptorUK:
It may well be a UAC issue, try installing MT4 in a directory other than Program Files, e.g. C:\MT4Installs\


I agree with you that might be a UAC problem.

But I'm not sure that installing MT in another folder would bypass UAC (it shouldn't, would be a security hole in MS Windows).

By the way I tried running MT by right-clicking on the exe and choosing "Run as administrator" and this should indeed bypass UAC.

Nevertheless, the problem is still there :(

Thanks.

 
spronti:


I agree with you that might be a UAC problem.

But I'm not sure that installing MT in another folder would bypass UAC (it shouldn't, would be a security hole in MS Windows).

By the way I tried running MT by right-clicking on the exe and choosing "Run as administrator" and this should indeed bypass UAC.

Nevertheless, the problem is still there :(

Thanks.

You need to read up on UAC . . . https://en.wikipedia.org/wiki/User_Account_Control

"Applications written with the assumption that the user will be running with administrator privileges experienced problems in earlier versions of Windows when run from limited user accounts, often because they attempted to write to machine-wide or system directories (such as Program Files) or registry keys (notably HKLM).[4] UAC attempts to alleviate this using File and Registry Virtualization, which redirects writes (and subsequent reads) to a per-user location within the user’s profile. For example, if an application attempts to write to “C:\program files\appname\settings.ini” and the user doesn’t have permissions to write to that directory, the write will get redirected to “C:\Users\username\AppData\Local\VirtualStore\Program Files\appname\settings.ini”."

 

I've given it a chance.

I've uninstalled MT and reinstalled it on C:\MetaTrader, copied back all my sources in the new folder.

All my indicators work fine but, as soon as I try the folowing:

//+------------------------------------------------------------------+
//| MyLibLib.mq4 |
//| Copyright 2012, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"

//+------------------------------------------------------------------+
//| My function |
//+------------------------------------------------------------------+
int MyCalculator(int value,int value2)
{
return(value+value2);
}
//+------------------------------------------------------------------+

And

#import "C:\MetaTrader4\experts\libraries\MyLib.mq4"
int MyCalculator(int value,int value2);

The indicator is not drown anymore with the error: cannot load library MyLib.mq4' (error 193)

Thanks anyway for you trying to help.

Regards

Stefano

 

I've never imported a function . . . but shouldn't the syntax be . . .

#import "C:\MetaTrader4\experts\libraries\MyLib.   ex4  " 
 
spronti:

Can anyone advise me on this error?

I have built a set of common functions that I’m going to call in all my own indicators.

Instead of recoding each function in every indicator, I put them all in a Library and now I’m trying to import the library and the functions in the indicator.

It compiles successfully. But, as soon as I run the indicator on a chart, I get the error in the Expert Log (and the indicator won’t draw):

cannot load library MyLib.mq4' (error 193)

What I’ve already checked is:

. Tools/Options/Expert Advisors tab: The flag “Allow DLL imports” is checked to true.

. When I drop the indicator on the Chart and the property dialog appears, on the Common tab, the “Allow DLL imports” is checked to true.

.The #import statement is coded with the fully qualified path to the library:

#import "C:\Users\Ste\AppData\Local\VirtualStore\Program Files (x86)\MetaTrader\experts\libraries\SP_Lib.mq4"

This is a common thing to do. You don't want to use #import in this case. It is easier to put the functions in an .mqh file and just #include that.

People do this with OrderReliable, for example.

https://www.mql5.com/en/forum/125463

The OrderReliable file at the bottom of the linked page tells you how to use it, eg where to put it and how to #include it.

Reason: