How can I call Alert() from my DLL code to report error messages?

 

Hi:


I am interested in accessing some of the native MQL4 functions from inside my DLL code: mainly to allow the reporting of error messages or status.


Here is a simplified example of what I would like to do. Note that it is an oversimplification for demonstration purposes. In actual practice the routine would be doing something like a Newton-Raphson fuzzy convergence algorithm. The Alert() would be called if the algorithm could not converge. The Print() would be called to describe progress (during testing).


__declspec(dllexport) int __stdcall doStuff(int x)
{
  if( x < 10 ) {
    Alert("ERROR: invalid parameter to do stuff, it must be 10 or greater.");
    return -1;
  }

  // Now do something with it.
  return x*x;
}

Unfortunately I do not know how to access the MQL4 functions inside of the DLL and could not find information about it in the on-line documentation or the book.


I know that I could probably generate my own window but that is not helpful in the general case where I might want to access other functions (like TimeCurr()).


Is this possible? I was thinking that I might be able to do something like this but thought that I would check first:


// This is NOT real code, I am making it up.
typedef void (__stdcall *AlertFctPtr)(...); // fct ptr typedef

// Sample DLL function.
__declspec(dllexport) int __stdcall MyAlert()
{
   HMODULE m = GetModuleHandle(NULL); // current module
   AlertFctPtr Alert = (AlertFctPtr) GetProcAddress(m,"Alert");
   if( Alert ) {
      Alert("Made it!");
      return 1; // it worked
   }
   return 0;
}

Any help would be greatly appreciated.


Thank you,


Joe

 
jlinoff wrote >>

Hi:

I am interested in accessing some of the native MQL4 functions from inside my DLL code: mainly to allow the reporting of error messages or status.

Here is a simplified example of what I would like to do. Note that it is an oversimplification for demonstration purposes. In actual practice the routine would be doing something like a Newton-Raphson fuzzy convergence algorithm. The Alert() would be called if the algorithm could not converge. The Print() would be called to describe progress (during testing).

Unfortunately I do not know how to access the MQL4 functions inside of the DLL and could not find information about it in the on-line documentation or the book.

I know that I could probably generate my own window but that is not helpful in the general case where I might want to access other functions (like TimeCurr()).

Is this possible? I was thinking that I might be able to do something like this but thought that I would check first:

Any help would be greatly appreciated.

Thank you,

Joe

I have the same problem, but I think, it can be solved with some IPC (Inter Process Communication) method, between the MT4 terminal and the DLL 's program, for ex. sockets, window messages, or pipes, etc... I plan to create an extension for mt4, that should be call all the mql4 functions from a C++ dll, or executeable application :) ... U can #import "winsock.dll" in the mql4 script, than u can use it to communicate with the dll over a TCP connection, but it sould be async. than the dll -s send info to the mt4 terminal over the socket, tells, which function to call, and the params... The mt4 terminal should send back the retuirn valuie. U can create a simple protocoll for it, I will use XML to pass the data in my program... Have FUN!

I have already tried to access the address of the mql4 functions with GetModuleHandle and GetProcAddress, but it seems not working... :( So must use IPC, u must do an async communicating channel, use the select() function. and fcntl to set the socket to async. u must process all the data what u can receive, and the application must signal the mt4 when no more data to send... WARNING: if u send exaple, a 1024 byte throw the socket, it is not garanted u receive it in 1 block on the other head, it could be, 1, 2,3 .... n block, exaple 2 x 512 byte... So u must recevie all the data. and than process it.

 
sabbath:

Hi Sabbath:


Thank you for the reply. I could not figure out how to do it so I simply worked around it by writing the messages in the MQL4 based on return codes.


Cheers,


Joe