Download MetaTrader 5
To add comments, please log in or register
Improve your rating. Execute orders in Freelance service!
lou jiyang
92
lou jiyang 2014.02.19 13:21  
#import "MT4iQuickChannel.dll"
   int QC_StartSender(string);
   int QC_ReleaseSender(int);
   int QC_SendMessage(int SenderHandle, string Message, int Flags);
#import

#import "kernel32.dll"
   void OutputDebugStringW(string msg);
#import

extern string  ChannelName = "QuickChannelTest";
extern bool    LogMessagesToDbgView = true;
int glbHandle = 0;

void init()
{
   glbHandle = QC_StartSender(ChannelName);
   if (glbHandle == 0) {
      Alert("Failed to get a QuickChannel sender handle");
   }
}

void deinit()
{
   QC_ReleaseSender(glbHandle);
   glbHandle = 0;
}

void start()
{
   if (glbHandle != 0) {
      string strMsg = StringConcatenate("我的天哪"  ,TimeToStr(TimeLocal(), TIME_SECONDS), ": " , Symbol() , "," , DoubleToStr(Bid, MarketInfo(Symbol(), MODE_DIGITS)) , "," , DoubleToStr(Ask, MarketInfo(Symbol(), MODE_DIGITS)));
      if (LogMessagesToDbgView) OutputDebugStringW("Message " + strMsg);
      int result = QC_SendMessage(glbHandle, strMsg, 0);
      if (result == 0) Alert("QuickChannel message failed");
      printf(strMsg);
   }     
}   
#import "MT4iQuickChannel.dll"
   int QC_StartReceiver(string, int);
   int QC_ReleaseReceiver(int);
   int QC_GetMessages3(int, string & arr[], int);
#import

#import "kernel32.dll"
   void OutputDebugStringW(string msg);
#import

extern string  ChannelName = "QuickChannelTest";
extern bool    LogMessagesToDbgView = true;

int glbHandle = 0;
string glbReceiveBuffer = "";

void init()
{
   glbReceiveBuffer = "12345678";
   for (int i = 0; i < 4; i++) glbReceiveBuffer = StringConcatenate(glbReceiveBuffer, glbReceiveBuffer);   
}

void deinit()
{
   QC_ReleaseReceiver(glbHandle);
   glbHandle = 0;
}

void start()
{

   if (glbHandle == 0) {
      glbHandle = QC_StartReceiver(ChannelName, WindowHandle(Symbol(), Period()));
   
      if (glbHandle == 0) {
         Alert("Failed to get a QuickChannel receiver handle");
      }
   }

   if (glbHandle != 0) {
      string arrBuffer[1];
      arrBuffer[0] = StringConcatenate(glbReceiveBuffer, ""); // Use copy of buffer template
      int res = QC_GetMessages3(glbHandle, arrBuffer, StringLen(arrBuffer[0]));
      
      if (res == 2) {
         Alert("QuickChannel buffer is not large enough!");
                     
      } else if (res == 1) {
               
      } else {
         string strMsgList = arrBuffer[0];

         if (strMsgList != "") {
         
            string Messages[];
            StringSplit(strMsgList, "\t", Messages);
         
            for (int i = 0; i < ArraySize(Messages); i++) {
               string strMsg = Messages[i];

               if (LogMessagesToDbgView) OutputDebugStringW("..." + strMsg);
         
               Comment(strMsg);
               Print(strMsg);
 }  }  } }}   

void StringSplit(string InputString, string Separator, string & ResultArray[])
{
   ArrayResize(ResultArray, 0);
   
   int lenSeparator = StringLen(Separator), NewArraySize;
   while (InputString != "") {
      int p = StringFind(InputString, Separator);
      if (p == -1) {
         NewArraySize = ArraySize(ResultArray) + 1;
         ArrayResize(ResultArray, NewArraySize);      
         ResultArray[NewArraySize - 1] = InputString;
         InputString = "";
      } else {
         NewArraySize = ArraySize(ResultArray) + 1;
         ArrayResize(ResultArray, NewArraySize);      
         ResultArray[NewArraySize - 1] = StringSubstr(InputString, 0, p);
         InputString = StringSubstr(InputString, p + lenSeparator);
         if (InputString == "") {
            ArrayResize(ResultArray, NewArraySize + 1);      
            ResultArray[NewArraySize] = "";
 }  }  }}
hi, coders, this is MT4iQuickChannel.dll sender-receiver message example,it worked in mt4 v509, but it do not work in v600+,i know the problem is about 16bit unicode, but i can't solve it,so can every body help me?
lou jiyang
92
lou jiyang 2014.02.19 13:34  
this is code,install into two MT,use for communicating with two terminal.
Files:
Lime
642
Lime 2014.02.19 22:29  
appleparty:
this is code,install into two MT,use for communicating with two terminal.

Thank you very much appleparty!
lou jiyang
92
lou jiyang 2014.02.20 05:10  

you are welcome,the code is not work in v600+, so if you can tell us how to solve the problem,i want thank you very much!

Michael Mick
5
Michael Mick 2014.02.20 18:43  

@gorick:

Great work to connect to an ORACLE DB! But how do you read/write from/to ORACLE with mql4?

And where did you get oraDLL.dll from?


THX in advance!


Michael

Dernie
33
Dernie 2014.02.21 11:33  

I've got the same questions as m.mick:

Where can I download oraDLL.dll and how is the implemenation of reading and writing with ORACLE-DB?

THX 4 helping me!

Rick
8
Rick 2014.02.25 02:54  
m.mick:

@gorick:

Great work to connect to an ORACLE DB! But how do you read/write from/to ORACLE with mql4?

And where did you get oraDLL.dll from?

THX in advance!

Michael

m.mick,

What I have given is a code snippet using Oracle Pro*C precompiler. Same as the EXEC SQL CONNECT. Look at the sample below. You write the code then run this through the Oracle Pro*C precompiler which produces C code that you then compile as part of your DLL in function calls. You need to know Oracle, get the Oracle DB and Client software, including the precompilers to do this. I have been using oracle for a very long time and prefer it to all others, simply because I am used to it.

Good luck.

    EXEC SQL WHENEVER NOT FOUND DO sql_error("ORACLE error--\n");

    EXEC SQL SELECT 'Col1', 'Col2'
             INTO :stringrec INDICATOR :string_ind /* note insert into array variable */
             FROM    dual
             WHERE   :bindval1 = :bindval1
             AND     :string1 = :string1;

The Oracle Pro*C precompiler generates C code from the above to interface Oracle using the OCI - Oracle Call Interface, its native API.

Rick
8
Rick 2014.02.27 11:10  
gorick:

m.mick,

What I have given is a code snippet using Oracle Pro*C precompiler. Same as the EXEC SQL CONNECT. Look at the sample below. You write the code then run this through the Oracle Pro*C precompiler which produces C code that you then compile as part of your DLL in function calls. You need to know Oracle, get the Oracle DB and Client software, including the precompilers to do this. I have been using oracle for a very long time and prefer it to all others, simply because I am used to it.

Good luck.

The Oracle Pro*C precompiler generates C code from the above to interface Oracle using the OCI - Oracle Call Interface, its native API.


I forgot to mention that you will need the 32bit version of the Oracle Instant Client, found here: http://www.oracle.com/technetwork/topics/winsoft-085727.html, the 64 bit will not work with the MetaTrader platform. The DB can be the 64 bit version. You have to know Oracle, it is a complex piece of software. You can develop for free, you just need to create a registration with Oracle, it is free to register. All Oracle downloads are free.
Dernie
33
Dernie 2014.03.12 13:24  

gorick:

Yeah, you are right, ORACLE is a complex software. I worked with ORACLE since a couple of years (but only SQL and PL/SQL), it's the best database. Unfortunately I havn't developed with Pro*C Compiler or DLL's. So it's quite difficult for me, to do this. But I gonna try! :-)

I've got a couple of questions regarding to your great work.

#import "oraDLL.ex4"
   int    oracle_connect(uchar user_name[], uchar user_pwd[], uchar db_service[]);
#import

If I ry to compile (Build 610) it, I'll receive error messages like "arrays are passed by reference only". Why? And what should I do? Why did you use uchar[] and not string? Maybe because of the Pro*C-Compiler?

How did you develop the DLL? With MT4 as well? I receive a *.ex4-File after compiling in meta editor.... .

If I receive the .c file from the Pro*C precompiler, what do I have to do with that file? How do I develop or generate a DLL with that piece of code?


Oracle Instant Client is mandatory for every client on which the oraDLL should be used. Right?


THX in advance!!!

Dernie
33
Dernie 2014.03.14 12:48  

If I use the ORACLE Pro*C Compiler, I'll get a lot of errors after inserting the generated code into the dll.

Here are some problems after compiling the dll:

- the declaration of UNAME_LEN, PWD_LEN and DBSTRING_LEN is missing

- is EXPORT the right word, I'll get an error; isn't extern the right word?

- connect1 (and 2 and 3) are of different types: in the declaration char ** and the usage (strncpy) only char *; and it's depricated, you should use strncpy_s

- sqlca is not declarated

- ...


Can anybody please help me?


THX in advance,

Michael

/ /123
To add comments, please log in or register