Problems calling function from self-developed library

 

I'm trying to group some common functions into a library of my own and for some silly reason can't get things to work. 

 

In my rlib.h file (located under "...\MQL4\Include" I do the following):

 

#property copyright "xxx"
#property link      "xxx"

#import "rlib.ex4"

int     subGetMagicNumber(int iMagic, string sSymbol, int iTimeFrame); 

 

 Then in my rlib.mq4 (located under "...\MQL4\LIbraries) I do the following: 

 

#property copyright "xxx" 
#property link      "xxx"
#property library
#import "rlib.ex4"

#include <stdlib.mqh>
#include <rlib.mqh>

int subGetMagicNumber (int iMagic, string sSymbol, int iTimeFrame)
{
  < ... some code goes here ... >
  return (StrToInteger(StringConcatenate(iMagic, iSymbol, iTimeFrame)));
}

 

Finally in my main EA code I do the following:

#property copyright "xxx" 

#property link      "xxx" 


#include <stdlib.mqh>
#include <rlib.mqh>

#import "rlib.ex4" 

static int    _iPeriod            = 0;
static string _sSymbol            = "";

string        _iMagicNumber       = 0; 

int init ()
{
   _sSymbol       = Symbol ();
   _iPeriod       = Period ();

   _iMagicNumber  = subGetMagicNumber (MagicNumber, _sSymbol, _iPeriod); 

 

Yet my EA dies with the following error:  

Can not find subGetMagicNumber in rlib.ex4

Unresolved import function call

 

Does anybody have any idea what I'm doing wrong here?

 
int subGetMagicNumber (int iMagic, string sSymbol, int iTimeFrame) export
{ 
  < ... some code goes here ... >
  return (StrToInteger(StringConcatenate(iMagic, iSymbol, iTimeFrame))); 
}
export is missed.
 

TheLobos:

In my rlib.h file (located under "...\MQL4\Include" I do the following):

#import "rlib.ex4"

int     subGetMagicNumber(int iMagic, string sSymbol, int iTimeFrame); 

 

 Then in my rlib.mq4 (located under "...\MQL4\LIbraries) I do the following: 

#property copyright "xxx" 
#property link      "xxx"
#property library
#import "rlib.ex4"

#include <stdlib.mqh>
#include <rlib.mqh>

int subGetMagicNumber (int iMagic, string sSymbol, int iTimeFrame)
{
  < ... some code goes here ... >
  return (StrToInteger(StringConcatenate(iMagic, iSymbol, iTimeFrame)));
}

 

Finally in my main EA code I do the following:

#property copyright "xxx" 

#property link      "xxx" 


#include <stdlib.mqh>
#include <rlib.mqh>

#import "rlib.ex4" 

static int    _iPeriod            = 0;
static string _sSymbol            = "";

string        _iMagicNumber       = 0; 

int init ()
{
   _sSymbol       = Symbol ();
   _iPeriod       = Period ();

   _iMagicNumber  = subGetMagicNumber (MagicNumber, _sSymbol, _iPeriod); 

  1. Perhaps you should read the manual. Importing Functions (#import) - Preprocessor - Language Basics - MQL4 Reference

    #import "file_name"
        func1 define;
        func2 define;
        ...          
        funcN define;
    #import          
    Your main EA does not list functions or end the #import. If the include file does it, then main should not have the #import
  2. Your include doesn't end the #import
  3. How can your library import itself?
  4. I've never seen any need for libraries (except when using other languages.) Just include your functions and be done.
 
WHRoeder:

  1. I've never seen any need for libraries (except when using other languages.) Just include your functions and be done.

This is actually a really good point. Doing it this way resolved everything in about 5 seconds. THANKS! 

 
@WHRoeder ... how bout 3rd party libraries? There it also makes sense. 
 
TheLobos:

This is actually a really good point. Doing it this way resolved everything in about 5 seconds. THANKS! 

This is not a paid q&a board, and if someone takes the time to answer your question and delivers the result on top, its just normal to thank for that and quite unpolite to ignore the answer. I and everybody else here have better things to do than wasting time for people who just take what suits best for them and who obviously do not appreciate such effort. Its rude, nothing else.  
 
What are you babbling about? The OP did thank me, and you quoted it.
 
WHRoeder:
What are you babbling about? The OP did thank me, and you quoted it.

I think that that "Doerk" is feeling a little "unappreciated" because the OP did not thank him as well for his posts.

@Doerk: I don't think that the OP meant any disrespect and was just happy that his problem was solved via a method that required the least amount of effort on his part, which just so happened to have been suggested by "WHRoeder".

As for the Q&A, whether you like it or not, forums do tend to be exactly that.

 

@WHRoeder - I am surely not "babbling", ok?

@FMIC - its absolutely ok that one takes the part which suits the needs best, of course. But a part of good behaviour is to recognize the actual answer one searched for and at least to thank for that. I dont think that I am that very wrong at this point.  

Reason: