how should we know show the relevant code... using SRC
![]() Play video | For large amount of code attach the file. |
I am fetching from Database using C/C++ Dll and then importing it into EA in MQL4.
The EA code is as:
#import "SampleMSDBCon.dll" int StoreIntoMSSQL(string ,string ,int ,string ,int ,int ,string,string); bool is_Insertdb_connected(); #import #import "ReadingSignalsFromDB.dll" //int FetchSignalsFromMS(string ,string ,int,string); int FetchSignalsFromMS(string ,string ,string); bool is_Fetchdb_connected(); #import int start { FetchFromDB(); } void FetchFromDB() { //Signal = FetchSignalsFromMS( MSSymbName,Ea_name,elapsedSec,readProc); Signal = FetchSignalsFromMS( MSSymbName,Ea_name,readProc); Print("Signal = ", Signal); Print("elapsedSec = ", elapsedSec); if(Signal == 2) { Print("Operation = Sell"); Print("fetching from DB successfull with RetCode1 = " ,Signal); Print("symbolName = ",MSSymbName,"Ea_name = ",Ea_name,"readProc = ",readProc); } else if(Signal == 1) { Print("Operation = Buy"); Print("fetching from DB successfull with RetCode1 = " ,Signal); Print("MSSymbName = ",MSSymbName,"Ea_name = ",Ea_name,"readProc = ",readProc); } else { Print("fetching from DB failed with RetCode1 = " ,Signal); } }
As the calling of DLL is working fine in older version of MQL4; so as per me, the error is somewhere in C/C++ Dll but i am not sure on it.
The DLL code is as follows:
int readSignalFromMSSQL(char *Symbol,char *Ea_name, char *pProcedure)
{
HRESULT hr = S_OK ;
_CommandPtr pCmd = NULL;
_ConnectionPtr pConnection = NULL;
_bstr_t strMessage, strAuthorID;
::CoInitialize(NULL);
long codRet = -1;
_ParameterPtr ParReturn1; //
_ParameterPtr Par1; // SYMBOL
_ParameterPtr Par2; // Ea_name
try
{
TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
hr = pConnection->Open("dsn=MS_DB;", "sa", "sql2012", adConnectUnspecified);
//hr = pConnection->Open("dsn=SimulatorDB;", "sa", "sql2012", adConnectUnspecified);
pConnection->CursorLocation = adUseClient;
TESTHR(pCmd.CreateInstance(__uuidof(Command)));
pCmd->CommandText = pProcedure;
pCmd->CommandType = adCmdStoredProc;
ParReturn1 = pCmd->CreateParameter( _bstr_t("@signal"), adInteger , adParamOutput, 0, codRet);
pCmd->Parameters->Append( ParReturn1 );
Par1 = pCmd->CreateParameter("@symbol",adChar, adParamInput, strlen(Symbol) , Symbol);
pCmd->Parameters->Append(Par1);
Par2 = pCmd->CreateParameter("@eaname",adChar, adParamInput, strlen(Ea_name) , Ea_name );
pCmd->Parameters->Append(Par2);
pCmd->ActiveConnection = pConnection;
hr = pCmd->Execute( 0, 0, adCmdStoredProc );
if( FAILED(hr) )
{
codRet = -2;
}
else
{
ParReturn1 = pCmd->Parameters->GetItem(_bstr_t("@signal")); //0
codRet = ParReturn1->GetValue();
}
}
catch(_com_error )
{
codRet = -3;
}
if (pConnection)
if (pConnection->State == adStateOpen)
pConnection->Close();
::CoUninitialize();
return((int)codRet);
}
extern "C" __declspec(dllexport) int FetchSignalsFromMS(char *Symbol,char *Ea_name ,char *pProcedure)
{
int ccc = readSignalFromMSSQL(Symbol,Ea_name,pProcedure);
//char intStr[12];
//itoa(ccc,intStr,10);
//char *strr = intStr+1 ;
//int elapsedSec = atoi(strr);
//int Signal = first(ccc);
return(ccc) ;
}
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register

Hello,
I am calling a C/C++ Dll in an EA in updated MQL4. But i am getting critical error in calling that DLL.
But if call the same Dll in earlier version of MQL4, it is calling perfect.
Please Help me regarding this.