3

I am trying to create a basic hello world dll using codeblocks and metatrader4 and trying to do it in a striped version. my compile .dll and .def are in the same dir as the .mq4 file.

in file test.mq4

#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict

//#import "gimmeDLL.dll"
//   string GetStringValue(string) define;
//#import

#import "gimmeDLL.dll"
    string GetStringValue(string) define;
#import

void OnStart()
  {
   GetStringValue();

  }

in the main.cpp of the dll

#define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;

#define MT4_EXPFUNC __declspec(dllexport)

void MT4_EXPFUNC GetStringValue()
  {
   cout << "Hello, World" << endl;
  }

in gimmeDLL.def I have

LIBRARY gimmeDLL

EXPORTS
    GetStringValue

error

'define' - semicolon expected   marketDump.mq4  6   34
'define' - declaration without type marketDump.mq4  6   34
'GetStringValue' - wrong parameters count   marketDump.mq4  11  4
  • Note: I am not trying to create an indicator. Nothing 'indicator' will assist me. I am looking for raw communication to the dll and nothing else. –  Jul 26 '14 at 16:52
  • While it might sound as a provocation, for a rapid test, a SCRIPT is a better MQL4-"wrapper" for your goal, than an EA, because in an EA-wrapped-HelloWorld, you rely on A) BEING LOGGED-ON onto an MT4/Server ( at a Broker Account ) + B) BEING RUN during MON/FRI MarketHours + C) BEING PATIENT to wait, until a FX-market sends a StreamQuote Event, so as to make MT4/Terminal process your line of code ....................................................................**Ref. below for another Answer on "How-To"** – user3666197 Aug 11 '14 at 19:26

2 Answers2

1

Do compile this as a SCRIPT, to avoid EA-dependencies

For a rapid test, a SCRIPT is a way better MQL4-"wrapper" for your goal, than an EA, because in an EA-wrapped-HelloWorld, you rely on

A) BEING LOGGED-ON onto an MT4/Server ( at an existing + live Broker Account )

+

B) BEING RUN during MON/FRI MarketHours

+

C) BEING PATIENT to wait, until a next FX-market event sends at least one StreamQuote Event,

so as to make your <localhost> MT4/Terminal process your single-line-of-code ...

So, "HOW-TO"?

#import "gimmeDLL.dll"                       // MQL4-import-section-start-marker--------
    string GetStringValue();                 //      interface definition for compile-time processing
#import                                      // MQL4-import-section-end-marker----------
void   OnInit() {                            // MQL4-on-init(), for pre-Build-578 Terminal, use rather int init(){ ...; return(0); } <code-constructor>
       Comment( "DLL-call test",             // MQL4-UI-printing facility
                "\nhas produced a string == [[[",
                GetStringValue(),
                "]]]"
              );
       }
user3666197
  • 1
  • 6
  • 50
  • 92
-1

You need to declare the list of functions you will be using like so:

> #import "file_name"
>     func1 define;
>     func2 define;
>     ...
>     funcN define;
> #import

Take a look at this: http://docs.mql4.com/basis/preprosessor/import

Dmitry
  • 1,513
  • 1
  • 15
  • 33
  • I figured there had to be some type of function prototyping going on, but it doesn't want to accept it http://i.imgur.com/xWPOZ2g.png –  Jul 27 '14 at 01:44
  • You have a syntax error. you have to close off the the #import "file_name" block with a #import statement. Look at the last line of the above and and also in the doc above. Also, remove the word define from your import statement leaving only "void HelloWorld();". – Dmitry Jul 27 '14 at 18:25
  • #import "gimmeDLL.dll" string GetStringValue(string) define; #import <- you mean close it with that ?? still get errors, I edited the code to represent the change since adding your suggestion. –  Jul 28 '14 at 06:33
  • I borrowed from the DLL sample code. I can get the sample code to work, but it doesn't seem to like 'Hello World'. Not sure what I am doing wrong. –  Jul 28 '14 at 06:38
  • Yes you need to close out the section with #import and you also need to remove the word define from: #import "gimmeDLL.dll" string GetStringValue(string) define; #import – Dmitry Jul 28 '14 at 14:18
  • "remove define from ~"? Your definition 'func1 define' has the word define in it, and so does my code above. I did copy/paste of your ^^ code there containing the 2 additional 'string' expressions and get the exact same error string GetStringValue(string) define; –  Jul 28 '14 at 17:00
  • 1
    I got it. I have no clue why they have 'define' in the function definition but you have to remove it to use it. freakin st00pid. But thank you, it does compile now. –  Jul 28 '14 at 17:10
  • While MQL4 language compilation has slightly got shifted on post-Build 572+ introduction of "a-*New*-MQL4" language, the **`#import "aDll.dll"`** / { Function syntax definition(s) } / **`#import`** *MetaLang.exe*-compiler pre-processor directive has not changed. Trial/errors above were IMHO rather copy/paste artifacts, **no real MQL4 programmer would ever experience any such mis-concept** in either phase of Dev/Test/Production. – user3666197 Aug 14 '14 at 17:20