Skip to content

Commit

Permalink
reorganize DLL imports
Browse files Browse the repository at this point in the history
  • Loading branch information
rosasurfer committed Dec 29, 2024
1 parent 62bea3d commit 6f4e852
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions mql4/include/rsf/core/expert.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ double _Ask; // ...


/**
* Global init() function for experts.
* Core initialization handler of experts.
*
* @return int - error status
*/
Expand Down Expand Up @@ -290,7 +290,7 @@ int start() {


/**
* Expert deinitialization
* Core deinitialization handler of experts.
*
* @return int - error status
*
Expand Down
4 changes: 2 additions & 2 deletions mql4/include/rsf/expander/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* @link https://docs.mql4.com/constants/errorswarnings/errorcodes
*/
#define ERR_NO_ERROR 0
//efine NO_ERROR ERR_NO_ERROR // in C++ already defined (Win32)
//efine NO_ERROR ERR_NO_ERROR // in C++ already defined (Win32 API)

// Trading errors
// Trade errors
#define ERR_NO_RESULT 1
// No status returned, unknown result. OrderModify() attempted to replace values already set. May also happen if the trade server changes during OrderModify().
#define ERR_COMMON_ERROR 2 // trade request failed (trade server error)
Expand Down
9 changes: 6 additions & 3 deletions mql4/include/rsf/functions/log.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
*
* @param string message - message
* @param int error [optional] - error code (default: none)
* @param int loglevel [optional] - loglevel to add to the message (default: debug)
* @param int loglevel [optional] - loglevel to add to the message (default: LOG_DEBUG)
*
* @return int - the same error
*/
int debug(string message, int error=NO_ERROR, int loglevel=LOG_DEBUG) {
// Note: This function MUST NOT call MQL library functions. Calling DLL functions is fine.
// Note: This function MUST NOT call MQL library functions. Calling DLL functions is OK.
if (!IsDllsAllowed()) {
Alert("debug(1) DLL calls are not enabled (", message, ", error: ", error, ")");
return(error);
Expand Down Expand Up @@ -83,7 +83,7 @@ int debug(string message, int error=NO_ERROR, int loglevel=LOG_DEBUG) {
* After return the internal MQL error as returned by GetLastError() is always reset.
*
* @param string caller - location identifier of the caller
* @param int error [optional] - trigger a specific error (default: no)
* @param int error [optional] - trigger a custom error (default: no)
* @param bool popOrder [optional] - whether the last order context on the order stack should be restored (default: no)
*
* @return int - the same error
Expand Down Expand Up @@ -655,6 +655,9 @@ bool SetLogfile(string filename) {
}


#import "kernel32.dll"
void OutputDebugStringA(string message);

#import "rsfMT4Expander.dll"
int ec_SuperLoglevel (int pid);
int ec_SuperLoglevelAlert (int pid);
Expand Down
1 change: 0 additions & 1 deletion mql4/include/rsf/stdfunctions.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -6886,7 +6886,6 @@ void __DummyCalls() {
int GetCurrentProcessId();
int GetCurrentThreadId();
int GetPrivateProfileIntA(string section, string key, int nDefault, string fileName);
void OutputDebugStringA(string message);
void RtlMoveMemory(int destAddress, int srcAddress, int bytes);
int WinExec(string cmdLine, int cmdShow);
bool WritePrivateProfileStringA(string section, string key, string value, string fileName);
Expand Down
1 change: 0 additions & 1 deletion mql4/include/rsf/win32api.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
int GetTempPathA(int bufferSize, string lpBuffer);
int LoadLibraryA(string lpLibFileName);
bool MoveFileA(string lpOldFileName, string lpNewFileName);
void OutputDebugStringA(string lpMessage); // without admin rights calls are ignored
bool ReadProcessMemory(int hProcess, int baseAddress, int lpBuffer[], int bytes, int lpNumberOfBytesRead[]);
void RtlMoveMemory(int destAddress, int srcAddress, int bytes);
int SleepEx(int milliseconds, int alertable);
Expand Down
12 changes: 6 additions & 6 deletions mql5/include/rsf/functions/log.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
*
* @param string message - message
* @param int error [optional] - error code (default: none)
* @param int loglevel [optional] - loglevel to add to the message (default: debug)
* @param int loglevel [optional] - loglevel to add to the message (default: LOG_DEBUG)
*
* @return int - the same error
*/
int debug(string message, int error=NO_ERROR, int loglevel=LOG_DEBUG) {
// Note: This function MUST NOT call MQL library functions. Calling DLL functions is fine.
// Note: This function MUST NOT call MQL library functions. Calling DLL functions is OK.
if (!IsDllsAllowed()) {
Alert("debug(1) DLL calls are not enabled (", message, ", error: ", error, ")");
return(error);
Expand Down Expand Up @@ -47,7 +47,7 @@ int debug(string message, int error=NO_ERROR, int loglevel=LOG_DEBUG) {
* After return the internal MQL error as returned by GetLastError() is always reset.
*
* @param string caller - location identifier of the caller
* @param int error [optional] - trigger a specific error (default: no)
* @param int error [optional] - trigger a custom error (default: no)
*
* @return int - the same error
*/
Expand All @@ -59,7 +59,7 @@ int catch(string caller, int error = NO_ERROR) {

if (error != 0) {
if (isRecursion) {
Alert("catch(1) recursion: ", caller, ", error: ", error, M_PI);
Alert("catch(1) recursion: ", caller, ", error: ", error);
return(debug("catch(1) recursion: "+ caller, error, LOG_ERROR));
}
isRecursion = true;
Expand All @@ -80,12 +80,12 @@ int catch(string caller, int error = NO_ERROR) {
string caption = "Strategy Tester "+ Symbol() +","+ PeriodDescription();
int pos = StringFind(message, ") "); // insert a line-wrap after the first closing function brace
if (pos != -1) message = StrLeft(message, pos+1) + NL + StrTrim(StrSubstr(message, pos+2));
message = TimeToStr(TimeLocal(), TIME_FULL) + NL + LoglevelDescription(level) +" in "+ ModuleName(true) +"::"+ message + (error ? " ["+ ErrorToStr(error) +"]" : "");
message = TimeToStr(TimeLocal(), TIME_FULL) + NL + LoglevelDescription(level) +" in "+ ModuleName(true) +"::"+ message + (error ? " ["+ sError +"]" : "");
PlaySoundEx("alert.wav");
MessageBoxEx(caption, message, MB_ICONERROR|MB_OK|MB_DONT_LOG);
}
else {
Alert(LoglevelDescription(level), ": ", Symbol(), ",", PeriodDescription(), " ", ModuleName(true), "::", message, (error ? " ["+ ErrorToStr(error) +"]" : ""));
Alert(LoglevelDescription(level), ": ", Symbol(), ",", PeriodDescription(), " ", ModuleName(true), "::", message, (error ? " ["+ sError +"]" : ""));
}

// set the error
Expand Down

0 comments on commit 6f4e852

Please sign in to comment.