#import questions

 

I'm trying to create a library file (.ex4) file to be used by #import syntax in the main program.

I have a problem in compiling the called library program. when trying to compile it, it complains "Start function not found". What should I do?

Should I also put these library programs in a separate directory?

Thanks!

 

can anyone help, please!

CodesGuru?

 

Library preprocessor directive

TheExponential:
I'm trying to create a library file (.ex4) file to be used by #import syntax in the main program.

I have a problem in compiling the called library program. when trying to compile it, it complains "Start function not found". What should I do?

Should I also put these library programs in a separate directory?

Thanks!

TheExponential,

I'm so sorry for the delay.

The error you have got because (I think) you didn't write this line on the top of your library program:

#property libraryTo create a library you have to:

1- Use #property library preprocessor directive on the top of your program (see the example).

2- Compile and save it in "MetaTrader 4\experts\libraries" path.

Example:

//+------------------------------------------------------------------+

//| Alerts.mq4 |

//| Coders Guru |

//| https://www.forex-tsd.com |

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

//|Use this code at your risk, I don't guarantee anything. | |

//+------------------------------------------------------------------+

#property copyright "Coders Guru"

#property link "https://www.forex-tsd.com"

#property library

#include //for MessageBoxA

#import "kernal32.dll"

//+------------------------------------------------------------------+

//|This function shows dialog box showing the data you passed |

//|Click "Retry if you want to see the messages next time, |

//|and click "Cancel" to disable the messages | |

//+------------------------------------------------------------------+

void Msg(string message)

{

//int MessageBoxA(int hWnd ,string lpText,string lpCaption,int uType);

static bool disable = false;

int result = 0;

if(!disable)

result = MessageBoxA(NULL,message,"Click cancel to disable Alerts!",MB_RETRYCANCEL|MB_ICONINFORMATION);

if(result==IDCANCEL)

disable=true;

}

//+------------------------------------------------------------------+

//|This function rerun trus when line1 cross line2 |

//|and false otherwise |

//|Ex: Print(Crossed (ExtMapBuffer1[0],ExtMapBuffer2[0])); |

//+------------------------------------------------------------------+

bool Crossed (double line1 , double line2 )

{

static string last_direction = "";

string current_dirction = "";

if(line1>line2)current_dirction = "up";

if(line1<=line2)current_dirction = "down";

if(current_dirction != last_direction)

{

//Alert("EMA Cross for "+Symbol()+" on the "+Period()+" minute chart.");

Msg("EMA Cross for "+Symbol()+" on the "+Period()+" minute chart.");

last_direction = current_dirction;

return (true);

}

else

{

return (false);

}

}

//+------------------------------------------------------------------+

 

Thanks once again, CodesGuru. I'll give it a try!

 

I have been able to compile the Library, but it fails in the import.

I have called my library program TELib.mq4. I've compiled and put it in the library path.

in using it, I wrote #import "TELib.ex4". And ends it with empty #import statement.

but it still complains when I refer to functions in the import.

Thanks.

 

I've also failed to use the standard stdlib.ex4 that MetaQuotes provides.

I tried to access ErrorDescription function, and it complains that the function is not defined.

Thanks again

Reason: